Improve HTTPS-on-HTTP parser error#12672
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12672 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 131 131
Lines 46688 46697 +9
Branches 2421 2422 +1
=======================================
+ Hits 46200 46209 +9
Misses 366 366
Partials 122 122
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
|
|
All code checks are green now; the only failing check I see is I tried to add |
What do these changes do?
Special-cases request parser errors where the incoming method bytes start with
\x16\x03, which is the common TLS ClientHello prefix. Both the pure-Python and Cython parser paths now report that HTTPS traffic was received on an HTTP port instead of showing the generic invalid method message.Are there changes in behavior for the user?
Yes. Misconfigured clients that send HTTPS traffic to an aiohttp HTTP server port now get a clearer 400 parser error message. There are no public API changes.
Is it a substantial burden for the maintainers to support this?
No. The change is a small error-message special case for a well-known byte prefix, with regression coverage for both parser implementations.
Related issue number
Fixes #10142.
Checklist
CONTRIBUTORS.txtCHANGES/folder<issue_or_pr_num>.<type>.rst(e.g.588.bugfix.rst)number after creating the PR
.bugfix: A bug fix for something the maintainers deemed animproper undesired behavior that got corrected to match
pre-agreed expectations.
.feature: A new behavior, public APIs. That sort of stuff..deprecation: A declaration of future API removals and breakingchanges in behavior.
.breaking: When something public is removed in a breaking way.Could be deprecated in an earlier release.
.doc: Notable updates to the documentation structure or buildprocess.
.packaging: Notes for downstreams about unobvious side effectsand tooling. Changes in the test invocation considerations and
runtime assumptions.
.contrib: Stuff that affects the contributor experience. e.g.Running tests, building the docs, setting up the development
environment.
.misc: Changes that are hard to assign to any of the abovecategories.
Local validation
pytest tests/test_http_parser.py::test_http_request_parser_tls_handshake_on_http_port -qfailed because the message was still the generic bad method error.AIOHTTP_NO_EXTENSIONS=1 PYTHONPATH=. pytest tests/test_http_parser.py -q-> 377 passed, 13 skipped, 4 deselected.PYTHONPATH=. pytest tests/test_http_parser.py -q-> 725 passed, 12 skipped, 6 deselected, 3 xfailed.PYTHONPATH=. pytest tests/test_http_exceptions.py -q-> 19 passed.black --check aiohttp/http_exceptions.py tests/test_http_parser.pypassed.git diff --checkreported only Windows LF-to-CRLF working-copy warnings.Drafted with OpenAI GPT-5; reviewed by puneetdixit200.