Skip to content

Commit

Permalink
fix: lowercase headers in response object (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
adbar authored Feb 26, 2024
1 parent bc387a2 commit 20d291f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/downloads_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_response_object():
resp = Response(my_html, 200, "https://example.org")
assert bool(resp) is True
resp.store_headers({"X-Header": "xyz"})
assert "X-Header" in resp.headers
assert "x-header" in resp.headers
resp.decode_data(True)
assert my_html.decode("utf-8") == resp.html == str(resp)
my_dict = resp.as_dict()
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_fetch():
for no_ssl in (True, False):
response = _send_urllib_request('https://httpbun.com/status/200', no_ssl, True, DEFAULT_CONFIG)
assert response.data == b''
assert response.headers["X-Powered-By"].startswith("httpbun")
assert response.headers["x-powered-by"].startswith("httpbun")
if pycurl is not None:
response1 = _send_pycurl_request('https://httpbun.com/status/200', True, True, DEFAULT_CONFIG)
assert response1.headers["x-powered-by"].startswith("httpbun")
Expand Down
4 changes: 2 additions & 2 deletions trafilatura/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def __str__(self):

def store_headers(self, headerdict):
"Store response headers if required."
# control or normalization here?
self.headers = headerdict
# further control steps here
self.headers = {k.lower(): v for k, v in headerdict.items()}

def decode_data(self, decode):
"Decode the bytestring in data and store a string in html."
Expand Down

0 comments on commit 20d291f

Please sign in to comment.