Repository navigation
Support absolute-form request targets - #396
Open
mayur-dhavan wants to merge 6 commits into
Open
mayur-dhavan wants to merge 6 commits into
mayur-dhavan wants to merge 6 commits into
Conversation
Added a regex to match absolute-form request targets and implemented the reduce_target_to_origin_form function to handle them according to RFC 9112.
This branch has not been deployed
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.
RFC 9112, section 3.2.2 requires a server to accept the absolute-form of a
request target:
Hypercorn currently places the entire target into the ASGI scope, so an
application routes on a path that is not a path:
With
root_path="/api"the two are concatenated into"/apihttp://example.org/one/two". The WebSocket handshake scope isaffected the same way.
This change adds
reduce_target_to_origin_form()inhypercorn/utils.pyand applies it where the HTTP and WebSocket scopes are built
(
protocol/http_stream.pyandprotocol/ws_stream.py). All protocolversions build their scopes through these two streams, so h2 and h3
requests pass through the same code path; the change itself was exercised
end-to-end over HTTP/1.1 and the HTTP/1.1 WebSocket upgrade.
An absolute-form target with an empty path becomes "/", matching the
origin-form rule in RFC 9112, section 3.2.1 (a proxy forwarding to an
origin server applies the same replacement, RFC 9110, section 7.7).
Origin-form (
/foo), asterisk-form (*) and authority-form(
example.org:443) targets are returned unchanged, so behaviour for theother target forms is untouched.
Tests: unit cases for the helper covering every target form, plus
scope-level tests for the HTTP and WebSocket streams that fail before the
change and pass after it.
Testing notes:
pytest tests/gives 210 passed with 2 failures,tests/asyncio/test_sanity.py::test_http2_websocketandtests/trio/test_sanity.py::test_http2_websocket, both raisingh2.exceptions.ProtocolError('Ordinary CONNECT MUST NOT include :scheme or :path'); both fail identically on a clean checkout of main (h2 libraryversion incompatibility, unrelated to this change).
mypyreports oneerror that also pre-exists on main:
protocol/http_stream.py:210: error: Missing key "trailers" for TypedDict "HTTPResponseStartEvent".black --checkandflake8pass on the changed files.