swift-server / swift-server/swift-http-server

Expose the negotiated HTTP version to request handlers

Open Beginner friendly
#113 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue kind/enhancement size/S
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.