mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-28 22:24:34 +01:00
Allow sending case insensitve headers
This commit is contained in:
parent
fe70f20aed
commit
a9bc34feb1
2 changed files with 18 additions and 1 deletions
|
@ -257,7 +257,8 @@ class RequestHandler(abc.ABC):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _merge_headers(self, request_headers):
|
def _merge_headers(self, request_headers):
|
||||||
return HTTPHeaderDict(self.headers, request_headers)
|
header_type = type(request_headers) if isinstance(request_headers, HTTPHeaderDict) else HTTPHeaderDict
|
||||||
|
return header_type(self.headers, request_headers)
|
||||||
|
|
||||||
def _calculate_timeout(self, request):
|
def _calculate_timeout(self, request):
|
||||||
return float(request.extensions.get('timeout') or self.timeout)
|
return float(request.extensions.get('timeout') or self.timeout)
|
||||||
|
|
|
@ -79,6 +79,22 @@ class HTTPHeaderDict(collections.UserDict, dict):
|
||||||
return super().__contains__(key.title() if isinstance(key, str) else key)
|
return super().__contains__(key.title() if isinstance(key, str) else key)
|
||||||
|
|
||||||
|
|
||||||
|
class CaseSensitiveDict(HTTPHeaderDict):
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
if isinstance(value, bytes):
|
||||||
|
value = value.decode('latin-1')
|
||||||
|
self.data[key] = str(value).strip()
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return self.data[key]
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
del self.data[key]
|
||||||
|
|
||||||
|
def __contains__(self, key):
|
||||||
|
return key in self.data
|
||||||
|
|
||||||
|
|
||||||
std_headers = HTTPHeaderDict({
|
std_headers = HTTPHeaderDict({
|
||||||
'User-Agent': random_user_agent(),
|
'User-Agent': random_user_agent(),
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
|
|
Loading…
Reference in a new issue