Repository navigation
Expose the negotiated HTTP version to request handlers - #125
Open
dioKaratzas wants to merge 2 commits into
Open
dioKaratzas wants to merge 2 commits into
dioKaratzas wants to merge 2 commits into
Conversation
dioKaratzas
force-pushed
the
expose-negotiated-http-version
branch
from
August 29, 2026 09:34
bb87508 to
add9ac9
Compare
gjcairo
approved these changes
Sep 7, 2026
Collaborator
|
Thanks @dioKaratzas ! |
gjcairo
enabled auto-merge (squash)
September 7, 2026 22:22
FranzBusch
reviewed
Sep 14, 2026
| /// Servers whose request context conforms to this capability surface the | ||
| /// application-level HTTP version negotiated for the connection carrying | ||
| /// the request. | ||
| public protocol NegotiatedHTTPVersion: RequestContext { |
Contributor
There was a problem hiding this comment.
I think Negotiated is potentially wrong here. If the server runs over bare TCP without TLS then nothing is negotiated necessarily. What about just HTTPVersion?
Contributor
Author
There was a problem hiding this comment.
Good point, renamed to HTTPServerCapability.HTTPVersion and reworded the docs so they no longer imply negotiation (041371f). Also rebased on latest main.
Motivation: `NIOHTTPServer.ConnectionContext` carries the application protocol negotiated for a connection as a `public let httpVersion`, but request handlers only ever receive a `RequestContext`, whose `connectionContext` is internal. `RequestContext` already surfaces the peer / local addresses and the validated peer certificate chain, but there was no capability for the negotiated version, so a handler had no way to tell which protocol it was serving. Modifications: - Added `HTTPServerCapability.NegotiatedHTTPVersion`, a request-context capability exposing `httpVersion`, following the shape of the existing `ConnectionInfo` and `PeerCertificate` capabilities. - Conformed `NIOHTTPServer.RequestContext` to it, forwarding to the connection context, and updated the capability lists in the `RequestContext` and `ConnectionContext` documentation. - Added a test asserting the version reported by the request context for every supported protocol: plaintext HTTP/1.1, HTTP/1.1 over TLS, HTTP/2 and HTTP/3. Result: Request handlers can read the negotiated HTTP version, and generic library code can constrain on the capability without depending on `NIOHTTPServer` directly. `ConnectionContext` stays internal to the handler surface, and the change is purely additive.
Motivation: The capability was named `NegotiatedHTTPVersion`, but nothing is necessarily negotiated: a server running over bare TCP without TLS serves plaintext HTTP/1.1 without any ALPN exchange. Modifications: - Renamed `HTTPServerCapability.NegotiatedHTTPVersion` to `HTTPServerCapability.HTTPVersion`. - Reworded the capability, conformance and test descriptions to refer to the HTTP version in use on the connection rather than the negotiated one. Result: The capability name and documentation describe the HTTP version accurately for both TLS and plaintext connections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
auto-merge was automatically disabled
October 14, 2026 16:27
Head branch was pushed to by a user without write access
dioKaratzas
force-pushed
the
expose-negotiated-http-version
branch
from
October 14, 2026 16:27
add9ac9 to
041371f
Compare
Contributor
Author
|
@FranzBusch @gjcairo rebased on latest |
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.
Resolves #113.
Adds
HTTPServerCapability.NegotiatedHTTPVersion, following the existingConnectionInfo/PeerCertificatepattern, and conformsNIOHTTPServer.RequestContextto it by forwarding to the connection context.ConnectionContextstays internal to the handler surface. Purely additive.Test plan: asserted the negotiated version from the request handler in the existing HTTP/1.1 and HTTP/2 end-to-end tests.