Return headers as lowercase byte sequences as required by ASGI

This commit is contained in:
Miguel Grinberg
2023-03-02 20:10:12 +00:00
parent 9398c96075
commit ddb3b8f442
2 changed files with 6 additions and 6 deletions

View File

@@ -93,10 +93,10 @@ class Microdot(BaseMicrodot):
header_list = []
for name, value in res.headers.items():
if not isinstance(value, list):
header_list.append((name, value))
header_list.append((name.lower().encode(), value.encode()))
else:
for v in value:
header_list.append((name, v))
header_list.append((name.lower().encode(), v.encode()))
if scope['type'] != 'http': # pragma: no cover
return

View File

@@ -83,10 +83,10 @@ class TestMicrodotASGI(unittest.TestCase):
if packet['type'] == 'http.response.start':
self.assertEqual(packet['status'], 200)
expected_headers = [
('Content-Length', '8'),
('Content-Type', 'text/plain; charset=UTF-8'),
('Set-Cookie', 'foo=foo'),
('Set-Cookie', 'bar=bar; HttpOnly')
(b'content-length', b'8'),
(b'content-type', b'text/plain; charset=UTF-8'),
(b'set-cookie', b'foo=foo'),
(b'set-cookie', b'bar=bar; HttpOnly')
]
self.assertEqual(len(packet['headers']), len(expected_headers))
for header in expected_headers: