Skip to content

Commit

Permalink
Skip headers where value is None, mimics requests, fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet committed Oct 1, 2023
1 parent 1a285d5 commit 06684cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions curl_cffi/requests/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(
normalize_header_value(v, encoding),
)
for k, v in headers.items()
if v is not None
]
else:
if isinstance(headers[0], (str, bytes)):
Expand Down
17 changes: 17 additions & 0 deletions tests/unittest/test_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from curl_cffi.requests import Headers


def test_headers():
headers = Headers()
headers['foo'] = 'bar'
headers['foo'] = 'baz'
assert headers['foo'] == 'baz'
assert headers.get('foo') == 'baz'
assert headers.get('bar') is None
assert headers


def test_headers_none_value():
headers = Headers({"foo": None, "bar": ""})
assert headers.get("foo") is None
assert headers["bar"] == ""

0 comments on commit 06684cd

Please sign in to comment.