[utils] HTTPHeaderDict: Handle byte values

This commit is contained in:
pukkandan 2023-07-30 03:18:10 +05:30
parent de20687ee6
commit 3f7965105d
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
2 changed files with 4 additions and 0 deletions

View file

@ -2344,6 +2344,8 @@ Line 1
def test_http_header_dict(self): def test_http_header_dict(self):
headers = HTTPHeaderDict() headers = HTTPHeaderDict()
headers['ytdl-test'] = b'0'
self.assertEqual(list(headers.items()), [('Ytdl-Test', '0')])
headers['ytdl-test'] = 1 headers['ytdl-test'] = 1
self.assertEqual(list(headers.items()), [('Ytdl-Test', '1')]) self.assertEqual(list(headers.items()), [('Ytdl-Test', '1')])
headers['Ytdl-test'] = '2' headers['Ytdl-test'] = '2'

View file

@ -65,6 +65,8 @@ class HTTPHeaderDict(collections.UserDict, dict):
self.update(kwargs) self.update(kwargs)
def __setitem__(self, key, value): def __setitem__(self, key, value):
if isinstance(value, bytes):
value = value.decode('latin-1')
super().__setitem__(key.title(), str(value)) super().__setitem__(key.title(), str(value))
def __getitem__(self, key): def __getitem__(self, key):