swift-server / swift-server/swift-http-server
Expose the negotiated HTTP version to request handlers
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 44
- Forks
- 13
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 8
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with NIOHTTPServer.RequestContext and the existing ConnectionInfo and PeerCertificate capability implementations mentioned in the issue. Expose ConnectionContext.httpVersion through the same capability pattern, or the minimal accessor proposed. Done means a request handler can read whether its connection negotiated HTTP/1.1, HTTP/2, or another supported version without accessing ConnectionContext directly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100