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: ensure requests use local copy of headers dict. #964

Closed
wants to merge 2 commits into from

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