drop duplicate Host headers when building the request - #13379
Draft
arshsmith1 wants to merge 2 commits into
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13379 +/- ##
=======================================
Coverage 98.99% 98.99%
=======================================
Files 132 132
Lines 49290 49293 +3
Branches 2566 2566
=======================================
+ Hits 48795 48798 +3
Misses 371 371
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
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.
What do these changes do?
ClientRequestBase._update_headerssets the Host header withheaders.pop(hdrs.HOST, host)and then callsself.headers.extend(headers).CIMultiDict.pop()removes only the first entry for a key, andClientSession._prepare_headersdeliberately keeps caller-supplied duplicates (it callsresult.add()when a name repeats). So a request built from a multidict holding twoHostentries keeps the second one after the pop, andextend()re-adds it, so the request goes out with twoHostheader lines. Multiple Host headers are a request-smuggling / host-confusion primitive, and RFC 9112 wants exactly one.popall()removes every caller-supplied copy beforeextend()runs, so a single canonical Host survives while a lone caller override still behaves the same.Are there changes in behavior for the user?
Only for the duplicate case. A single Host header, whether derived from the URL or supplied once by the caller, is unchanged. Several caller
Hostheaders now collapse to the first rather than all going out on the wire.Is it a substantial burden for the maintainers to support this?
No. It swaps one call for its
popallequivalent and adds a regression test next to the existing Host-header tests.Related issue number
None.
Checklist
CONTRIBUTORS.txtCHANGES/folder