What I'm trying to do
Read, inside a request handler, the application protocol negotiated for the
connection (HTTP/1.1 vs HTTP/2, etc.).
The gap
NIOHTTPServer.ConnectionContext already carries it as a public let httpVersion: HTTPVersion, but a handler can't reach it: the only thing it receives is a RequestContext, whose connectionContext is internal. RequestContext surfaces the peer/local addresses (ConnectionInfo) and the validated peer certificate chain (PeerCertificate), but there's no capability for the negotiated version — so a handler has no way to tell which protocol it's serving.
Suggested shape
Expose it following the existing capability pattern, e.g.:
extension HTTPServerCapability {
public protocol NegotiatedHTTPVersion: RequestContext {
var httpVersion: NIOHTTPServer.HTTPVersion { get }
}
}
extension NIOHTTPServer.RequestContext: HTTPServerCapability.NegotiatedHTTPVersion {
public var httpVersion: NIOHTTPServer.HTTPVersion {
self.connectionContext.httpVersion
}
}
This keeps ConnectionContext internal to the handler surface and stays consistent with how ConnectionInfo / PeerCertificate are exposed. A minimal alternative would be just the public var httpVersion accessor. Happy to open a PR for whichever shape you prefer.
What I'm trying to do
Read, inside a request handler, the application protocol negotiated for the
connection (HTTP/1.1 vs HTTP/2, etc.).
The gap
NIOHTTPServer.ConnectionContextalready carries it as apublic let httpVersion: HTTPVersion, but a handler can't reach it: the only thing it receives is aRequestContext, whoseconnectionContextisinternal.RequestContextsurfaces the peer/local addresses (ConnectionInfo) and the validated peer certificate chain (PeerCertificate), but there's no capability for the negotiated version — so a handler has no way to tell which protocol it's serving.Suggested shape
Expose it following the existing capability pattern, e.g.:
This keeps
ConnectionContextinternal to the handler surface and stays consistent with howConnectionInfo/PeerCertificateare exposed. A minimal alternative would be just thepublic var httpVersionaccessor. Happy to open a PR for whichever shape you prefer.