Skip to content

Expose the negotiated HTTP version to request handlers #113

Description

@mob-connection

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerskind/enhancementImprovements to existing feature.size/SSmall task. (A couple of hours of work.)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions