Skip to content

Commit d737f5a

Browse files
headers_raw_to_dict actually regressed, fix
1 parent c0d3047 commit d737f5a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

w3lib/http.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from base64 import b64encode
4-
from collections import defaultdict
54
from collections.abc import Mapping, MutableMapping, Sequence
65
from io import BytesIO
76
from typing import Any, Union, overload
@@ -51,17 +50,21 @@ def headers_raw_to_dict(headers_raw: bytes | None) -> HeadersDictOutput | None:
5150
return {}
5251

5352
headers = iter(BytesIO(headers_raw).readline, b"")
54-
result_dict = defaultdict(list)
53+
result_dict = {}
5554

5655
for header in headers:
57-
parts = header.split(b":", 1)
58-
if len(parts) != 2:
56+
key, sep, value = header.partition(b":")
57+
if not sep:
5958
continue
6059

61-
key, value = map(bytes.strip, parts)
62-
result_dict[key].append(value)
60+
key, value = key.strip(), value.strip()
6361

64-
return dict(result_dict)
62+
if key in result_dict:
63+
result_dict[key].append(value)
64+
else:
65+
result_dict[key] = [value]
66+
67+
return result_dict
6568

6669

6770
@overload

0 commit comments

Comments
 (0)