fix: ignore Content-Length/Transfer-Encoding in CONNECT 2xx proxy responses (RFC-9110)#12397
fix: ignore Content-Length/Transfer-Encoding in CONNECT 2xx proxy responses (RFC-9110)#12397OfekDanny wants to merge 3 commits intoaio-libs:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12397 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 134 134
Lines 46616 46639 +23
Branches 2429 2430 +1
=======================================
+ Hits 46114 46137 +23
Misses 373 373
Partials 129 129
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Merging this PR will not alter performance
Comparing Footnotes
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| Per RFC-9110 §9.3.6 a client MUST ignore any Content-Length or | ||
| Transfer-Encoding header fields in a successful response to CONNECT. |
There was a problem hiding this comment.
The test doesn't seem to validate any of this. It just verifies the function is called with the given arguments.
Summary
Per RFC-9110 §9.3.6:
When a proxy server returns a
200 Connection establishedresponse with aContent-Lengthheader, aiohttp's HTTP parser attempts to read that many bytes as a response body. This corrupts the tunnel and causes the subsequent TLS handshake to fail.The fix adds
skip_payload=Trueto theset_response_paramscall used when reading the CONNECT response, which instructs the HTTP parser to treat the response as having no body regardless of any framing headers.Changes
aiohttp/connector.py: addskip_payload=Trueto CONNECT response parsingtests/test_proxy.py: add regression test (test_https_connect_skip_payload_on_200) that verifiesset_response_paramsis called withskip_payload=TrueFixes #8472