diff --git a/python-ecosys/requests/requests/__init__.py b/python-ecosys/requests/requests/__init__.py index a9a183619..ac39efaad 100644 --- a/python-ecosys/requests/requests/__init__.py +++ b/python-ecosys/requests/requests/__init__.py @@ -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) diff --git a/python-ecosys/requests/test_requests.py b/python-ecosys/requests/test_requests.py index 513e533a3..e10301c28 100644 --- a/python-ecosys/requests/test_requests.py +++ b/python-ecosys/requests/test_requests.py @@ -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() @@ -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()