diff --git a/src/microdot_asgi.py b/src/microdot_asgi.py index 89b4be8..ecc9f31 100644 --- a/src/microdot_asgi.py +++ b/src/microdot_asgi.py @@ -59,8 +59,9 @@ class Microdot(BaseMicrodot): headers = NoCaseDict() content_length = 0 for key, value in scope.get('headers', []): - headers[key] = value - if key.lower() == 'content-length': + key = key.decode().title() + headers[key] = value.decode() + if key == 'Content-Length': content_length = int(value) if content_length and content_length <= Request.max_body_length: diff --git a/tests/test_microdot_asgi.py b/tests/test_microdot_asgi.py index 843927f..ae753cf 100644 --- a/tests/test_microdot_asgi.py +++ b/tests/test_microdot_asgi.py @@ -53,9 +53,9 @@ class TestMicrodotASGI(unittest.TestCase): 'type': 'http', 'path': '/foo/bar', 'query_string': b'baz=1', - 'headers': [('Authorization', 'Bearer 123'), - ('Cookie', 'session=xyz'), - ('Content-Length', 4)], + 'headers': [(b'Authorization', b'Bearer 123'), + (b'Cookie', b'session=xyz'), + (b'Content-Length', b'4')], 'client': ['1.2.3.4', 1234], 'method': 'POST', 'http_version': '1.1', @@ -114,9 +114,9 @@ class TestMicrodotASGI(unittest.TestCase): scope = { 'type': 'http', 'path': '/foo/bar', - 'headers': [('Authorization', 'Bearer 123'), - ('Cookie', 'session=xyz'), - ('Content-Length', 4)], + 'headers': [(b'Authorization', b'Bearer 123'), + (b'Cookie', b'session=xyz'), + (b'Content-Length', b'4')], 'client': ['1.2.3.4', 1234], 'method': 'POST', 'http_version': '1.1',