Skip to content

httpclient: Don't modify the caller's HTTPRequest - #3937

Merged
bdarnell merged 4 commits into
tornadoweb:masterfrom
bdarnell:claude/project-thread-eoml46
Nov 25, 2026
Merged

bdarnell merged 4 commits into
tornadoweb:masterfrom
bdarnell:claude/project-thread-eoml46

Conversation

@bdarnell

Copy link
Copy Markdown
Member

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

bdarnell and others added 4 commits November 25, 2026 16:06
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
@bdarnell
bdarnell merged commit 8a4e5a1 into tornadoweb:master Nov 25, 2026
23 checks passed
@bdarnell
bdarnell deleted the claude/project-thread-eoml46 branch November 25, 2026 19:04
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