Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lowercase headers in response object #513

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading