Repository navigation
httpclient: Don't modify the caller's HTTPRequest - #3937
Merged
bdarnell merged 4 commits intoNov 25, 2026
Merged
Conversation
AsyncHTTPClient.fetch said it didn't modify the caller's object, but it assigned a copy of the headers back onto the caller's HTTPRequest and then added Host, Authorization and other headers to it. Fetching the same request again (for example, after changing its URL and clearing its credentials) sent the previous request's Host and Authorization. websocket_connect did the same. Add HTTPRequest.copy(), which copies the headers and a dict of ssl_options along with the request, and use it in both places. Also stop the HTTPRequest constructor from adding If-Modified-Since to the headers object the caller passed in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VamvWoYWj1JiKa2j3tWtGh
Always copy the headers argument into a new HTTPHeaders object, so the caller's dict is never used or modified directly, and only copy the request in fetch() when it came from the caller. Fix a broken reference in the release notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VamvWoYWj1JiKa2j3tWtGh
…read-eoml46 # Conflicts: # tornado/httpclient.py
The setter accepts a dict or HTTPHeaders and the getter is typed to return HTTPHeaders, so always convert, and copy even when given an HTTPHeaders so the caller's object is never shared with the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VamvWoYWj1JiKa2j3tWtGh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AsyncHTTPClient.fetch said it didn't modify the caller's object, but it assigned a copy of the headers back onto the caller's HTTPRequest and then added Host, Authorization and other headers to it. Fetching the same request again (for example, after changing its URL and clearing its credentials) sent the previous request's Host and Authorization. websocket_connect did the same.
Add HTTPRequest.copy(), which copies the headers and a dict of ssl_options along with the request, and use it in both places. Also stop the HTTPRequest constructor from adding If-Modified-Since to the headers object the caller passed in.
Claude-Session: https://claude.ai/code/session_01VamvWoYWj1JiKa2j3tWtGh