mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-27 21:59:17 +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):
|
||||
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):
|
||||
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)
|
||||
|
||||
|
||||
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({
|
||||
'User-Agent': random_user_agent(),
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
|
|
Loading…
Reference in a new issue