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

Update __init__.py to prevent changes to caller's headers dict #963

Closed
wants to merge 1 commit into from

Conversation

agadsby
Copy link

@agadsby agadsby commented Jan 12, 2025

The Micropython version of urequests behaves differently to Python's in that if a headers dict is passed in it gets extended by entries such as Content-Length that are added to the caller's dict.

Change is to take a local copy of any headers passed in to urequests() otherwise the caller's headers gets incorrectly extended.

The snip below illustrates the problem.

import urequests as requests
# test to demonstrate that micropython urequest incorrectly modifies passed headers dict
headers = {}

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

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 12, 2025
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