Skip to content

Conversation

agadsby
Copy link

@agadsby agadsby commented Jan 14, 2025

Currently requests() only creates a local copy of headers() if no headers dict is passed in. This means that any headers dict passed in will have extra entries added incorrectly. The code snip below illustrates the problem:

import requests
# test to demonstrate that micropython urequest incorrectly modifies called headers
headers = {}

response = requests.get(
            url="http://www.google.com",
            headers=headers,
            data="string",
        )
print(headers)
assert headers == {}, "requests returned changed headers to parent"

This fix uses a copy of the called headers to process the actual request.

Need to take a local copy of any headers passed in to requests() otherwise the caller's list gets incorrectly extended or modified.

Signed-off-by: Andrew Gadsby <[email protected]>
@agadsby agadsby closed this Jan 14, 2025
@agadsby agadsby deleted the patch-1 branch January 14, 2025 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant