diff --git a/tests/test_http_response.py b/tests/test_http_response.py index 4f514e0..2efc4ec 100644 --- a/tests/test_http_response.py +++ b/tests/test_http_response.py @@ -16,7 +16,7 @@ class TestHTTPResponse(DaphneTestCase): Lowercases and sorts headers, and strips transfer-encoding ones. """ return sorted([ - (name.lower(), value) + (name.lower(), value.strip()) for name, value in headers if name.lower() != "transfer-encoding" ]) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index af967fa..409aac4 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -52,7 +52,7 @@ class TestWebsocket(DaphneTestCase): # {name: [value1, value2, ...]} and check if they're equal. transformed_scope_headers = collections.defaultdict(list) for name, value in scope["headers"]: - transformed_scope_headers[name] = [] + transformed_scope_headers.setdefault(name, []) # Make sure to split out any headers collapsed with commas for bit in value.split(b","): if bit.strip(): @@ -61,8 +61,8 @@ class TestWebsocket(DaphneTestCase): for name, value in (headers or []): expected_name = name.lower().strip().encode("ascii") expected_value = value.strip().encode("ascii") - transformed_request_headers[expected_name] = [] # Make sure to split out any headers collapsed with commas + transformed_request_headers.setdefault(expected_name, []) for bit in expected_value.split(b","): if bit.strip(): transformed_request_headers[expected_name].append(bit.strip())