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

requests: Do not leak header modifications when calling request() #946

Closed
Closed
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
2 changes: 2 additions & 0 deletions python-ecosys/requests/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def request(
):
if headers is None:
headers = {}
else:
headers = dict(headers)

redirect = None # redirection url, None means no redirection
chunked_data = data and getattr(data, "__next__", None) and not getattr(data, "__len__", None)
Expand Down
9 changes: 9 additions & 0 deletions python-ecosys/requests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def chunks():
), format_message(response)


def test_do_not_modify_headers_argument():
original_headers = {}
headers = dict(original_headers)
requests.request("GET", "https://example.com", headers=original_headers)

assert headers == original_headers


test_simple_get()
test_get_auth()
test_get_custom_header()
Expand All @@ -153,3 +161,4 @@ def chunks():
test_overwrite_get_headers()
test_overwrite_post_json_headers()
test_overwrite_post_chunked_data_headers()
test_do_not_modify_headers_argument()
Loading