HTTP/3

On this page

PhotonHTTP serves HTTP/3 (RFC 9114) over QUIC. It has no QUIC stack of its own: QUIC, TLS 1.3, loss recovery and congestion control come from Network.framework (NWProtocolQUIC) on macOS, and from ngtcp2 over OpenSSL 3.5 on Linux (Running on Linux). HTTP/3 framing, stream handling and QPACK header compression are written in Swift in the HTTP3 and QPACK targets. The QUIC listener runs next to the TCP listeners in the same Server, and HTTPS responses tell clients where to find it with an Alt-Svc header.

Why Network.framework: implementing QUIC ourselves would need a TLS 1.3 server that exposes its handshake secrets (no public API does), packet protection, RFC 9002 recovery, migration and anti-amplification. ROADMAP §6 chose Option A (Network.framework) after a spike; Option B (our own QUIC) was rejected. The spike's findings are in quic-spike.md, and the adapter's in notes/nw-transport.md.

How it fits together

LayerWhereRole
QUIC listenerQUICListener (NetworkTransport)NWListener with newConnectionGroupHandler: one NWConnectionGroup, so one QUICConnection, per QUIC connection. Binds UDP with requiredLocalEndpoint
QUIC connectionQUICConnection, QUICStreamTransportA MultiplexedTransport: inbound streams as a demand-driven sequence, our own unidirectional streams, FIN, RESET_STREAM / STOP_SENDING codes, MAX_STREAMS credit
QUIC optionsQUICConfiguration (source)ALPN (h3), flow-control windows, stream limits, idle timeout
HTTP/3HTTP3, H3Configuration (Sources/HTTP3)Control and QPACK streams, SETTINGS, request streams to HTTPHandler, GOAWAY, limits
QPACKQPACKEncoder, QPACKDecoder, QPACKDynamicDecoder (Sources/QPACK)Static table, Huffman, the decoder side of the dynamic table
DiscoveryAltSvc middleware (AltSvc.swift)Alt-Svc: h3=":PORT"; ma=SECONDS on HTTPS responses

HTTP3 is a MultiplexedConnectionProtocol; a ServerListener.multiplexed(...) entry pairs it with the QUIC listener. The handler chain is the same one HTTP/1.1 and HTTP/2 use, so every component works over HTTP/3 unchanged. Requests report version .http3 and the connection's negotiated ALPN is h3.

Requirements

Binding rules are the same as for TCP: QUICListener defaults to 127.0.0.1, and loopback never triggers the macOS firewall prompt. Binding 0.0.0.0 or :: with an unsigned, freshly built binary can (the firewall prompt). Tests and local checks therefore bind loopback and port 0.

Turning it on in http-config.json

{
  "host": "127.0.0.1",
  "port": 8080,
  "root": "Public",
  "tls": { "identity": "certs/server.p12", "passwordEnv": "SWS_P12_PASSWORD", "port": 8443 },
  "http3": true
}

"http3": true uses every default. The object form:

KeyTypeDefaultMeaning
http3.enabledbooltruefalse turns it off (as do "http3": false and null)
http3.portinteger 0–65535 or nullTLS port numberUDP port. null or absent takes the TLS listener's bound port, including one picked when tls.port is 0
http3.altSvcMaxAgeinteger seconds86400ma of the Alt-Svc header
http3.qpackMaxTableCapacityinteger 0–10485760QPACK dynamic table offered to clients; 0 decodes with the static table only
http3.qpackBlockedStreamsinteger 0–10000Request streams that may wait for QPACK inserts at once (only with a table)

The full config reference is in Running on a Mac. http3 is a restart-only key: SIGHUP reports a change to it and ignores it.

What else the executable sets (makeListeners in ServerMain.swift):

How clients find it: Alt-Svc

Browsers do not try QUIC first. They connect over TCP and TLS, see

alt-svc: h3=":8443"; ma=86400

on the response, and use HTTP/3 for that origin for the next ma seconds (RFC 7838, RFC 9114 §3.1.1). The AltSvc middleware adds the header only to responses on TLS connections that are not HTTP/3: HTTPS over HTTP/1.1 or HTTP/2. Cleartext responses never carry it (a client must not take an alternative for an https origin from an unauthenticated connection), and HTTP/3 responses do not repeat it. It is added to every such response, error pages included, at the cost of one atomic load and a copy of the pre-rendered bytes.

let altSvc = AltSvc(port: 8443, maxAge: 86_400)  // port known up front
let altSvc = AltSvc(maxAge: 86_400)              // or: nothing until advertise(port:)
altSvc.advertise(port: boundPort)                 // the first call wins

Streams

Connection setup and SETTINGS

For each connection the server opens three unidirectional streams: its control stream (type 0x00, starting with SETTINGS), and its QPACK encoder (0x02) and decoder (0x03) streams. They stay open for the life of the connection. The SETTINGS it sends:

SettingValue
SETTINGS_QPACK_MAX_TABLE_CAPACITYqpackMaxTableCapacity (default 0)
SETTINGS_MAX_FIELD_SECTION_SIZEmaxFieldSectionSize (default 16,384)
SETTINGS_QPACK_BLOCKED_STREAMSqpackBlockedStreams when the table is on, else 0
SETTINGS_ENABLE_CONNECT_PROTOCOL1, only when extended CONNECT is enabled (below); otherwise not sent

From the client, the server accepts exactly one control stream (SETTINGS first, once), one QPACK encoder and one decoder stream. A second one of any of them, or a client push stream, is H3_STREAM_CREATION_ERROR; a missing first SETTINGS is H3_MISSING_SETTINGS; one of them closing is H3_CLOSED_CRITICAL_STREAM. HTTP/2-only frame types and setting identifiers are errors as RFC 9114 requires. Reserved (GREASE) and unknown unidirectional streams are refused with STOP_SENDING H3_STREAM_CREATION_ERROR; unknown frames are skipped without buffering. The peer's SETTINGS_MAX_FIELD_SECTION_SIZE is honoured: a response head larger than it is replaced by a bare 500.

The server never pushes. It tracks the client's MAX_PUSH_ID only to validate CANCEL_PUSH.

Request streams

Each client-initiated bidirectional stream is one request: HEADERS, optional DATA, optional trailers. The handler runs as a child task of the stream's task, next to a body reader that feeds request.body under backpressure (the reader stops reading the QUIC stream while bodyQueueCapacity chunks wait). Request trailers reach HTTPRequestBody.trailers. priority request fields and PRIORITY_UPDATE frames (RFC 9218) are applied (see Known limitations for what they can change).

Every failure is signalled as the H3Failure table in H3Failure.swift says: a stream error resets one stream with a code; a connection error closes QUIC with a code. Cancellation works both ways (#0104): a client RESET_STREAM or STOP_SENDING cancels the handler's task (even while it is still computing, since QUICStreamTransport watches for peer aborts), and a handler that is cancelled or throws CancellationError resets its stream with H3_REQUEST_CANCELLED. A response body that fails after its head was sent is reset with H3_INTERNAL_ERROR, so a truncated response never looks complete.

GOAWAY and graceful shutdown

When the server drains (requestShutdown(), or SIGINT/SIGTERM in the executable) or a connection has had no open request for timeouts.idle:

  1. The server sends GOAWAY with the next unprocessed client stream ID. With timeouts.goawayGrace set, it first sends GOAWAY with the largest possible ID (2^62 − 4), waits the grace period, then sends the final one (RFC 9114 §5.2).
  2. Streams at or above that ID are reset with H3_REQUEST_REJECTED (safe to retry); requests below it run to completion.
  3. When the last one finishes, or timeouts.drain passes, the server waits timeouts.closeLinger (or until the client closes) so the client can read the GOAWAY and the last responses, then closes with H3_NO_ERROR.

The server's own drainTimeout still bounds the whole drain: at that deadline every connection is cancelled. See Lifecycle.

Extended CONNECT and WebSockets (RFC 9220)

WebSockets run over HTTP/3 with extended CONNECT. HTTP3 advertises SETTINGS_ENABLE_CONNECT_PROTOCOL = 1 when the handler chain contains an ExtendedConnectProvider, which WebSocketUpgrade is, and so is a ReverseProxy with a websocket mount. H3Configuration.enableConnectProtocol = true forces it on. Without it, a request carrying :protocol is malformed.

An extended CONNECT reaches the handler like any request, with request.connectProtocol set. A 2xx response with a .tunnel body keeps the request stream open as a byte stream: DATA payloads in, one DATA frame per send out, FIN as end of stream. Request body limits do not apply to a tunnel; the send timeout does. The same WebSocketUpgrade endpoint serves HTTP/1.1, HTTP/2 and HTTP/3; see the WebSockets guide.

QPACK

Responses are encoded with the static table only (RFC 9204 Appendix A, 99 entries): an indexed line when the table has the name and value, a name reference when it has the name, a literal otherwise. Strings are Huffman-coded when that is shorter. authorization, cookie and set-cookie are always literals with the never-indexed bit. The encoder never inserts into a dynamic table, so the server's encoder stream carries only its type byte.

Requests are decoded with the static table by default. The server advertises SETTINGS_QPACK_MAX_TABLE_CAPACITY = 0, any dynamic reference is QPACK_DECOMPRESSION_FAILED, and nothing is shared between request streams.

The dynamic table (decoder side, #0106) is off by default and turned on by a non-zero capacity:

"http3": { "qpackMaxTableCapacity": 4096, "qpackBlockedStreams": 16 }
H3Configuration(qpackMaxTableCapacity: 4_096, qpackBlockedStreams: 16)

With it on, the connection keeps a table (a ring over one byte arena of twice the capacity, sized once) behind a Mutex, reads the client's encoder stream (Set Dynamic Table Capacity, Insert With Name Reference, Insert With Literal Name, Duplicate), and sends Section Acknowledgment, Stream Cancellation and Insert Count Increment on its decoder stream. A request whose field section refers to inserts that have not arrived yet waits for them; that wait counts against timeouts.header, and at most qpackBlockedStreams requests may wait (one more is QPACK_DECOMPRESSION_FAILED). Homebrew curl (nghttp3) uses the table when it is offered (H3CurlTests.curlUsesTheQPACKDynamicTable).

It is off by default because it adds connection-shared state, a lock per field section and blocked streams. Decoding a dynamic section serializes head decoding across the streams of one connection.

Limits, timeouts and abuse defences

HTTP2.md ("HTTP/3 default limits" and "HTTP/3 abuse limits") is the authoritative list, with the wire code for each. In summary, for a custom server (H3Configuration, H3Timeouts, H3AbuseLimits); in the executable only the two QPACK values and closeLinger are configurable.

H3Configuration

SettingDefaultWhen it is exceeded
maxConcurrentRequestStreams100QUIC MAX_STREAMS is raised to this at the start and by one per finished request; a stream beyond it is reset H3_REQUEST_REJECTED
maxFieldSectionSize16,384431 when the pseudo-header fields make a valid request, else H3_MESSAGE_ERROR
maxEncodedFieldSectionLength65,536One HEADERS frame (the only frame buffered whole): connection error H3_EXCESSIVE_LOAD
maxRequestBodySize10 MiB413 (declared content-length before the handler runs; an undeclared body when it grows past)
maxUnreadBodySize64 KiBUnread request body discarded after the response; past it, STOP_SENDING H3_NO_ERROR
bodyQueueCapacity4 chunksRead-ahead between the stream and the handler
receiveSize16 KiBMost bytes asked for per stream receive
qpackMaxTableCapacity0Dynamic table off; at most 1 MiB
qpackBlockedStreams0One more blocked stream is QPACK_DECOMPRESSION_FAILED
enableConnectProtocolfalseTurned on automatically by an ExtendedConnectProvider in the chain

H3Timeouts

Handler time itself is never limited. nil turns a limit off.

TimeoutDefaultRuns whileWhen it passes
header10 sA request stream has not delivered its HEADERS (not renewed by progress)RESET_STREAM H3_REQUEST_REJECTED
idle30 sThe connection has no open requestGOAWAY, then close H3_NO_ERROR
body30 sThe handler waits for request body bytes (renewed per chunk)408, or H3_REQUEST_CANCELLED once the response started
send30 sOne response send waits (slow reader or send budget)RESET_STREAM H3_REQUEST_CANCELLED
unreadBody2 sUnread body is discarded after the responseSTOP_SENDING H3_NO_ERROR
drainoffRequests below the final GOAWAY finishClose H3_NO_ERROR (off: the server's drain deadline decides)
goawayGraceoffBetween the provisional and the final GOAWAYThe final GOAWAY
closeLinger1 s (executable: drainTimeout)After the drain, until the client closesClose H3_NO_ERROR

H3AbuseLimits

Counted per connection in a fixed window (window, 10 s) that starts at the first event. Each H3_EXCESSIVE_LOAD below closes the connection. nil turns a limit off; H3AbuseLimits.disabled turns them all off.

LimitDefaultCounts
maxAbortedRequestsPerWindow100Rapid reset: request streams the client resets or stops before the response completes, or ends without a request
maxIgnoredUniStreamsPerWindow16Reserved and unknown unidirectional streams
maxQPACKInstructionsPerWindow1,000Instructions on the client's QPACK encoder and decoder streams
maxControlFramesPerWindow1,000Control-stream frames, unknown ones included
maxUnknownRequestFramesPerWindow1,000Reserved and unknown frames on request streams
maxUnknownFrameLength16 KiBDeclared length of one unknown frame, any stream (skipped, never buffered)
maxConnectionSendBuffer4 MiBResponse bytes in sends not yet completed, across the connection; further sends wait, and timeouts.send resets stalled streams
maxIdleConnections1,000Connections of one HTTP3 value with no open request; the longest-idle one is shut down gracefully

A QPACK decoder-stream backlog over 64 KiB (the client does not read it) is also H3_EXCESSIVE_LOAD.

QUIC transport (QUICConfiguration, QUICListener.Configuration)

These bound what a client can make Network.framework buffer.

SettingDefaultMeaning
maxStreamsBidirectional100initial_max_streams_bidi; replenished by the adapter as streams finish (Network.framework does not)
maxStreamsUnidirectional8initial_max_streams_uni (HTTP/3 needs at least 3)
initialMaxData4 MiBConnection receive window
initialMaxStreamDataBidirectionalRemote / Local256 KiBPer-stream receive window
initialMaxStreamDataUnidirectional64 KiBPer unidirectional stream
idleTimeoutMilliseconds30,000QUIC max_idle_timeout
sendChunkSize64 KiBA larger send is split; each chunk waits for Network.framework to accept it
pendingStreamLimitstreams + 2Inbound streams held before HTTP/3 takes them; more are reset H3_REQUEST_REJECTED
pendingConnectionLimit (listener)64Accepted connections not yet taken; more are closed at once

In a custom server

Add the HTTP3 product (it brings QPACK) next to HTTPServer and NetworkTransport in your package, as in A custom server package. This server serves HTTPS (HTTP/1.1 and HTTP/2 by ALPN) and HTTP/3 on the same port number, with a tuned H3Configuration:

import HTTP1
import HTTP2
import HTTP3
import HTTPCore
import HTTPServer
import NetworkTransport
import StaticFiles

@main
struct MySite {
    static func main() async throws {
        // PKCS#12 loaded in memory only; never the keychain.
        let identity = try TLSIdentity(pkcs12Path: ".test-identity/server.p12", password: "sws-test-password")
        let files = try StaticFiles(root: "Public")
        let altSvc = AltSvc(maxAge: 3_600)   // adds nothing until advertise(port:)

        var h3 = H3Configuration(maxRequestBodySize: 1 << 20,
                                 qpackMaxTableCapacity: 4_096, qpackBlockedStreams: 16)
        h3.timeouts.idle = .seconds(60)
        h3.timeouts.drain = .seconds(5)

        let listeners: [ServerListener] = [
            .byteStream(name: "https") { bind in
                try TCPListener(configuration: .init(host: "127.0.0.1", port: 8443),
                                tls: TLSConfiguration(identity: identity, alpn: bind.alpnTokens))
            },
            .multiplexed(name: "h3", protocol: HTTP3(configuration: h3)) { bind in
                // The HTTPS port number, over UDP.
                try QUICListener(configuration: .init(host: "127.0.0.1", port: bind.boundAddresses[0].port,
                                                      quic: QUICConfiguration(alpn: bind.alpnTokens)),
                                 identity: identity)
            },
        ]
        let server = Server(listeners: listeners, protocols: [TLSNegotiated(HTTP2(), fallback: HTTP1())]) {
            altSvc
            files
        }
        try await withThrowingDiscardingTaskGroup { group in
            group.addTask { try await server.run() }
            group.addTask {
                let addresses = try await server.waitUntilRunning()   // in listener order
                altSvc.advertise(port: addresses[1].port)
                for address in addresses { print("listening \(address)") }
            }
        }
    }
}

This snippet type-checks against this checkout (2026-11-13). Add the SIGINT/SIGTERM handling from Examples/custom-server/Sources/MySite/MySite.swift for a graceful drain.

Testing it

The system curl (/usr/bin/curl) has no HTTP/3. Homebrew's does (ngtcp2 and nghttp3):

scripts/make-test-identity.sh             # .test-identity/server.p12, self-signed, memory-only use
swift build -j 2 --product photon
scripts/guarded.sh -t 120 -- .build/debug/photon --config Root/http-config.tls.json

In another terminal (Root/http-config.tls.json uses TCP and UDP 8443):

curl -sk -o /dev/null -D - https://127.0.0.1:8443/ | grep -i alt-svc
# alt-svc: h3=":8443"; ma=86400

/opt/homebrew/opt/curl/bin/curl --http3-only -sk -o /dev/null -w '%{http_version} %{http_code}\n' https://127.0.0.1:8443/
# 3 200

--http3-only fails rather than falling back to TCP, so a 3 proves QUIC was used; --http3 tries QUIC and falls back. -k accepts the self-signed test certificate without changing any trust settings. Browsers need a trusted certificate before they will use the Alt-Svc alternative; see the TLS guide.

These checks were run against a loopback server with the test identity on 2026-11-13: the HTTPS response (HTTP/2) carried alt-svc: h3=":PORT"; ma=600 as configured, --http3-only got HTTP/3 200 with no alt-svc header, a cleartext response had none, and SIGINT stopped the server cleanly.

The test suites

SuiteWhat it covers
HTTP3Tests (in-memory)Frame parser, control streams, connection state, request streams, limits, abuse limits, cancellation, shutdown, priorities, QPACK dynamic table, WebSockets, proxying, Alt-Svc. Driven over InMemoryMultiplexedTransport, so close codes are checked exactly
HTTP3Tests over real QUICH3CurlTests (Homebrew curl: GET, body echo, 20 parallel requests, dynamic table, shutdown mid-request), H3QUICCancellationTests, H3QUICPriorityTests, H3QUICWebSocketTests (an in-repo QUIC client)
QPACKTestsStatic table, codec, stream instructions, RFC 9204 Appendix B examples for the dynamic table, fuzzing
NetworkTransportTestsQUICTransportTests, MultiplexedTransportConformanceTests (the same scenarios against QUIC and the in-memory transport), QUICCloseCodeTests
scripts/guarded.sh -t 600 -- swift test -j 2 --filter HTTP3Tests

Real-QUIC tests bind 127.0.0.1 port 0 and load .test-identity in memory (the test support runs scripts/make-test-identity.sh when it is missing). Suites that drive curl are skipped when /opt/homebrew/opt/curl/bin/curl does not exist.

The four known issues. A full swift test reports 4 known issues. They are not failures: they are the four parameter combinations (two close modes × codes 0x100 and 0x107) of QUICCloseCodeTests.applicationCloseCode, which wraps one expectation in withKnownIssue(..., isIntermittent: true). The test runs curl through a loopback UDP relay, decrypts what the server sent after closing with curl's key log, and records that our application close code never reaches the peer (the limitation below). If a macOS release starts sending it, the known issue stops being recorded and the test says so.

Known limitations

Performance

MeasurementResultRecord
Shipped binary, one curl process, 16 parallel requests on one QUIC connection, 626-byte fileabout 8,600 req/s over HTTP/3, against about 32,300 for HTTPS from the same curl (load average about 7)M5-listeners
Network.framework per-stream cost (spike)0.4–0.8 ms per stream round trip (concurrent vs sequential), about 590 server-side allocations per stream, mostly inside Network.frameworkquic-spike
QPACK decode of a 10-field request head661 ns static only; 114 ns from the dynamic tableM10-qpack-dynamic
QPACK encode, same head955 nsM10-qpack-dynamic
HTTP/3 frame parse11.87 ns per frame whole; 41.55 ns fed in 37-byte chunksM10-qpack-dynamic

The M5 HTTP/3 figure is limited partly by curl (one QUIC connection on one thread) and partly by the per-stream cost; it is not a load benchmark. Proper HTTP/3 load numbers are #0105. More in Performance notes.

Standards