Repository navigation
Conversation
FuNK3Y
force-pushed
the
aiohttp-redirect-host
branch
from
October 27, 2026 07:06
3e90d21 to
67224fe
Compare
request_raw() added the Host header to the headers dict it was given, which is the same dict _request() passes again for each redirect. The Host of the original URL was therefore still present when following a redirect to another host, and was sent to that host instead of its own name. Work on a copy of the headers in request_raw() so the caller's dict is left unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: FuNK3Y <fun__key@hotmail.com>
FuNK3Y
force-pushed
the
aiohttp-redirect-host
branch
from
October 27, 2026 07:08
67224fe to
09a943d
Compare
FuNK3Y
marked this pull request as ready for review
October 27, 2026 07:09
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.
Summary
When
ClientSessionfollows a 301/302/303 redirect to a different host, the redirected request is sent with theHostheader of the original URL.request_raw()addsHostto theheadersdict it receives, and_request()passes the same dict again for every redirect. Because of theif "Host" not in headerscheck, the stale value is kept. This change makesrequest_raw()work on a copy of the headers, so the caller's dict stays unchanged.I faced the problem when trying to download a release from a GitHub repo.
Testing
I tested on CPython with
asyncio.open_connectionstubbed and a CPython-compatible copy of the module (bytes%formatting with str arguments only works on MicroPython). The stub returns302 Location: http://b.example/xfora.example:GET /xwas sent withHost: a.exampleGET /xis sent withHost: b.exampleI did not test on a MicroPython port or board.
Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.
🤖 Generated with Claude Code