For nearly three decades, the web transport stack rested on an implicit division of labor between the operating system kernel and user-space applications: TCP (RFC 9293) provided a single, strictly ordered, reliable byte stream per 4-tuple (Source IP, Source Port, Destination IP, Destination Port), TLS (RFC 5246 / RFC 8446) layered cryptographic record framing atop that TCP socket, and HTTP/1.1 or HTTP/2 (RFC 9113) mapped application semantics onto the encrypted connection. While HTTP/2 solved application-layer head-of-line blocking by multiplexing concurrent logical streams over a single TCP connection, it exacerbated transport-layer head-of-line blocking: because the kernel's TCP stack knows nothing about HTTP/2 stream boundaries, a single lost IP packet stalls delivery of every active HTTP/2 stream until that exact TCP sequence number is retransmitted and acknowledged.
In 2026, high-throughput backend systems, global edge CDNs, real-time streaming media pipelines, and mobile clients operate natively on HTTP/3 (IETF RFC 9114) over QUIC Version 1 (IETF RFC 9000, 0x00000001) and QUIC Version 2 (IETF RFC 9369, 0x6b3343cf). By relocating stream multiplexing, loss recovery (RFC 9002), congestion control, and an embedded TLS 1.3 cryptographic key schedule (RFC 9001 & RFC 8446) into an encrypted UDP datagram substrate, QUIC eliminates cross-stream head-of-line blocking, collapses transport and cryptographic connection establishment into a 1-RTT (or 0-RTT resumed) handshake, survives client IP/port roaming across Wi-Fi and cellular networks via Connection IDs, and resists carrier middlebox ossification by encrypting nearly the entire transport header.
HTTP/1.1 vs. HTTP/2 vs. HTTP/3 Protocol Stack Architecture
This deep-dive engineering guide examines the exact binary packet headers, variable-length integer (varint) encodings, HKDF-SHA256 initial secret and header-protection derivations, 62-bit Stream ID bitmasks, HTTP/3 control and framing registries, QPACK out-of-order dynamic table synchronization (RFC 9204), unreliable datagram extensions (RFC 9221), Probe Timeout (PTO) and congestion window equations (RFC 9002), and zero-round-trip service discovery via DNS HTTPS resource records (RFC 9460, RRType 65) and Alt-Svc (RFC 7838). Every byte layout, hexadecimal constant, error code, and cryptographic test vector in this article is verified directly against the official IETF RFC 7838, RFC 8446, RFC 8470, RFC 9000, RFC 9001, RFC 9002, RFC 9114, RFC 9204, RFC 9221, RFC 9369, and RFC 9460 specifications.
1. Why HTTP/2 Over TCP Suffers From Transport-Layer Head-of-Line (HoL) Blocking and Kernel Ossification
To understand why HTTP/3 had to replace TCP rather than merely iterate on HTTP/2 framing, consider how a kernel TCP socket processes incoming segments when a connection carries $N$ multiplexed HTTP/2 streams (for example, an HTML document, three CSS stylesheets, six JavaScript modules, and twenty REST/gRPC API calls):
- Single Sequenced Byte-Stream Abstraction: In HTTP/2 (RFC 9113), the user-space HTTP engine interleaves
HEADERSandDATAframes from Stream 1, Stream 3, Stream 5, and Stream 7 into a single TLS record stream, which is written to a single TCP socket buffer. To the Linux or macOS kernel TCP stack, there is only one contiguous 32-bit sequence-number space. - Transport-Layer Head-of-Line (HoL) Blocking Under Packet Loss: Suppose the server transmits three consecutive UDP/IP-sized TCP segments: Segment $A$ (carrying Stream 1 bytes
0..1199), Segment $B$ (carrying Stream 3 bytes0..1199), and Segment $C$ (carrying Stream 5 bytes0..1199). If Segment $A$ is dropped in transit while Segments $B$ and $C$ arrive intact at the client NIC, the client kernel holds Segments $B$ and $C$ in the TCP out-of-order receive queue (ofo_queue). Even though Stream 3 and Stream 5 have 100% of their bytes sitting in kernel memory—and even if they carry complete TLS records—the kernelread()/epollinterface cannot deliver a single byte of Segment $B$ or Segment $C$ to user space until Segment $A$ is retransmitted at least one full round-trip time (1 RTT) later. Worse, because TLS 1.2/1.3 over TCP authenticates records sequentially using an implicit per-record sequence counter, user space could not decrypt record $B$ out of order even if the kernel exposed raw out-of-order TCP payload slices. - Handshake Latency Inflation (2-RTT to 3-RTT Cold Start): Establishing a cold HTTPS connection over TCP requires an initial 1-RTT TCP 3-way handshake (
SYN$\rightarrow$SYN-ACK$\rightarrow$ACK) before the client can even transmit the TLSClientHello. With TLS 1.3 (RFC 8446), the cryptographic handshake adds 1 additional RTT (2 RTTs total before the first HTTP request byte is sent, or 3 RTTs under TLS 1.2). - Middlebox Ossification and 4-Tuple Binding: Decades of enterprise firewalls, NAT gateways, and carrier middleboxes inspect unencrypted TCP header fields (sequence numbers,
ACKnumbers, TCP options, window scaling, and flags) and silently drop or rewrite packets that use unfamiliar TCP extensions. Furthermore, because a TCP connection is cryptographically and structurally identified by its 4-tuple (SrcIP:SrcPort,DstIP:DstPort), switching a mobile device from Wi-Fi (192.0.2.15:54112) to 5G cellular (203.0.113.88:41009) invalidates the 4-tuple and forces every active TCP/TLS/HTTP/2 connection to tear down and re-handshake from scratch.
| Architectural Dimension | HTTP/1.1 Over TCP + TLS 1.2/1.3 | HTTP/2 (RFC 9113) Over TCP + TLS 1.3 | HTTP/3 (RFC 9114) Over QUIC (RFC 9000 / RFC 9369) |
|---|---|---|---|
| Underlying L4 Transport | 6 parallel TCP connections per origin (RFC 9293) | Single multiplexed TCP connection per origin | UDP datagrams carrying independent encrypted QUIC streams |
| Cold / Resumed Handshake RTTs | 2–3 RTTs cold (1 RTT TCP + 1–2 RTT TLS) | 2 RTTs cold (1 RTT TCP + 1 RTT TLS 1.3); 1 RTT resumed | 1 RTT cold (transport + TLS 1.3 unified); 0 RTT resumed |
| Head-of-Line (HoL) Blocking Scope | Per-connection HTTP request HoL + TCP HoL | Eliminates HTTP HoL, but 1 lost TCP segment blocks all active streams | Per-stream only: a lost UDP packet stalls only the stream(s) whose frames were inside that packet |
| Header Compression Engine | None (raw ASCII field lines) | HPACK (RFC 7541): 61-entry 1-indexed static table; strictly ordered dynamic table | QPACK (RFC 9204): 99-entry 0-indexed static table (0..98); out-of-order safe via streams 0x02 & 0x03 |
| Network Roaming & IP Change | 4-tuple bound; IP/port change resets connection | 4-tuple bound; IP/port change resets all multiplexed streams | Connection IDs (0–20 bytes): seamless Wi-Fi $\leftrightarrow$ 5G migration with 64-bit PATH_CHALLENGE / PATH_RESPONSE |
| Loss Recovery & Retransmission Ambiguity | Reuses TCP sequence numbers on retransmit (Karn's algorithm ambiguity) | Reuses TCP sequence numbers on retransmit | Strictly monotonic 62-bit Packet Numbers: retransmitted STREAM frames get a brand-new packet number |
2. QUIC v1 (RFC 9000) & QUIC v2 (RFC 9369) Wire Format: Long/Short Packet Headers, 62-Bit Variable-Length Integers, and the 1,200-Byte Anti-Amplification Rule
In IETF RFC 9000 Section 12 and Section 17, every QUIC packet is encapsulated inside a standard UDP datagram payload in network byte order (big-endian). Multiple QUIC packets from different encryption levels (Initial, 0-RTT, Handshake, 1-RTT) can be coalesced back-to-back inside a single UDP datagram during the handshake because Long Header packets carry an explicit variable-length Length field.
Variable-Length Integer Encoding (varint, RFC 9000 Section 16)
To keep frame headers compact while supporting 62-bit stream offsets, packet numbers, and flow-control limits up to $2^{62}-1$ ($4,611,686,018,427,387,903$), RFC 9000 Section 16 (Table 4) defines a prefix-coded variable-length integer format. The two most significant bits (2MSB) of the first byte encode the base-2 logarithm of the byte length ($2^{\text{2MSB}} \in \{1, 2, 4, 8\}$ bytes), leaving $6, 14, 30,$ or $62$ usable bits for the unsigned integer value:
First-Byte 2MSB |
Total Byte Length | Usable Value Bits | Representable Decimal & Hexadecimal Range (RFC 9000 Table 4) |
|---|---|---|---|
0b00 (mask 0x00) |
1 byte (8 bits) |
6 bits |
0 to 63 (0x00 to 0x3f) — covers single-byte frame types and small stream IDs |
0b01 (mask 0x40) |
2 bytes (16 bits) |
14 bits |
0 to 16,383 (0x0000 to 0x3fff) — covers UDP payload lengths and error codes (e.g., 0x0100) |
0b10 (mask 0x80) |
4 bytes (32 bits) |
30 bits |
0 to 1,073,741,823 (0x00000000 to 0x3fffffff) |
0b11 (mask 0xc0) |
8 bytes (64 bits) |
62 bits |
0 to 4,611,686,018,427,387,903 ($2^{62}-1$, 0x3fffffffffffffff) |
Long Header Packets (Pre-1-RTT) vs. 1-RTT Short Header Packets
QUIC defines two top-level packet header structures distinguished by the most significant bit (0x80, Header Form) of Byte 0:
+=======================================================================+
| QUIC LONG HEADER PACKET (RFC 9000 Section 17.2 Figure 13) |
| Used for: Initial, 0-RTT, Handshake, and Retry packets |
+-----------------------------------------------------------------------+
| Byte 0: |
| Bit 7 (0x80): Header Form = 1 (Long Header) |
| Bit 6 (0x40): Fixed Bit = 1 (MUST be 1 except Version Neg.) |
| Bits 5..4 (0x30): Long Packet Type (2 bits - differs in v1 vs v2!) |
| Bits 3..0 (0x0f): Type-Specific Bits (2 Reserved=00 + 2 PN Length) |
+-----------------------------------------------------------------------+
| Bytes 1..4: Version (32 bits) |
| - QUIC v1 (RFC 9000): 0x00000001 |
| - QUIC v2 (RFC 9369): 0x6b3343cf (first 4B of SHA256("QUICv2 ...")) |
| - Version Negotiation: 0x00000000 |
+-----------------------------------------------------------------------+
| Byte 5: Destination Connection ID Length (8-bit uint, 0..20 bytes) |
| Variable (0..160 bits): Destination Connection ID (DCID) |
| Next 1 Byte: Source Connection ID Length (8-bit uint, 0..20 bytes) |
| Variable (0..160 bits): Source Connection ID (SCID) |
| Type-Specific Payload: |
| - Initial: Token Length (varint) + Token + Length (varint) + |
| Packet Number (1..4B, header-protected) + AEAD Payload |
+=======================================================================+
+=======================================================================+
| QUIC 1-RTT SHORT HEADER PACKET (RFC 9000 Section 17.3.1 Figure 19) |
| Used for: All post-handshake application data |
+-----------------------------------------------------------------------+
| Byte 0: |
| Bit 7 (0x80): Header Form = 0 (Short Header) |
| Bit 6 (0x40): Fixed Bit = 1 |
| Bit 5 (0x20): Spin Bit (passive RTT measurement bit, Sec. 17.4) |
| Bits 4..3 (0x18): Reserved Bits (MUST be 00 before header prot.) |
| Bit 2 (0x04): Key Phase (toggles on live 1-RTT AEAD key update) |
| Bits 1..0 (0x03): Packet Number Length (encoded as length - 1: 0..3)|
+-----------------------------------------------------------------------+
| Variable (0..160 bits): Destination Connection ID (length known impl.)|
| Bytes (1..4B): Packet Number (8..32 bits, header-protected) |
| Variable (8.. bits): 1-RTT AEAD-Protected Frame Payload + 16B AuthTag |
+=======================================================================+How QUIC Version 2 (RFC 9369) Defeats Middlebox Ossification
During early QUIC Version 1 (0x00000001) deployments, network operators discovered that some firewalls and deep-packet inspection (DPI) appliances had already hardcoded assumptions about the byte value 0x00000001 at bytes 1..4, the 2-bit Long Header packet type values (0x00 for Initial), and the QUIC v1 Initial salt—using them to decrypt client Initial packets and inspect or block the embedded TLS ClientHello SNI.
To prevent the internet from ossifying around QUIC Version 1's unencrypted header bits, the IETF published RFC 9369 (QUIC Version 2, May 2023). Rather than assigning version number 0x00000002, RFC 9369 sets the 32-bit Version field to 0x6b3343cf (the first 4 bytes of SHA-256("QUICv2 version number")), deliberately rotates the 2-bit Long Header Type field values, and replaces all HKDF salts and labels:
| Protocol Parameter | QUIC Version 1 (RFC 9000 & RFC 9001) | QUIC Version 2 (RFC 9369 Section 3) |
|---|---|---|
| 32-Bit Wire Version Field | 0x00000001 |
0x6b3343cf (first 4 bytes of SHA-256("QUICv2 version number")) |
Long Header Initial Type (2 bits) |
0x00 (0b00, RFC 9000 Section 17.2 Table 3) |
0b01 (0x01, RFC 9369 Section 3.2) |
Long Header 0-RTT Type (2 bits) |
0x01 (0b01) |
0b10 (0x02) |
Long Header Handshake Type (2 bits) |
0x02 (0b10) |
0b11 (0x03) |
Long Header Retry Type (2 bits) |
0x03 (0b11) |
0b00 (0x00) |
20-Byte initial_salt |
0x38762cf7f55934b34d179ae6a4c80cadccbb7f0a |
0x0dede3def700a6db819381be6e269dcbf9bd2ed9 |
| HKDF Expansion Labels | "quic key", "quic iv", "quic hp", "quic ku" |
"quicv2 key", "quicv2 iv", "quicv2 hp", "quicv2 ku" |
| Retry Integrity Tag AEAD Key & Nonce | Key: 0xbe0c690b9f66575a1d766b54e368c84eNonce: 0x461599d35d632bf2239825bb |
Key: 0x8fb4b01b56ac48e260fbcbcead7ccc92Nonce: 0xd86969bc2d7c6d9990efb04a |
Mandatory 1,200-Byte Minimum Initial Datagram Size & 3x Anti-Amplification Rule (RFC 9000 Sections 8.1 & 14.1)
Because UDP is connectionless and source IP addresses can be spoofed, an attacker could forge a small UDP packet carrying a fake QUIC Initial packet with a victim's source IP, tricking the server into sending a large certificate chain (4–8 KB) to the victim. To neutralize UDP reflection/amplification attacks and verify Path MTU simultaneously, RFC 9000 Section 14.1 mandates that clients and servers MUST expand the payload of all UDP datagrams carrying ack-eliciting Initial packets to at least 1,200 bytes (using PADDING frames 0x00 or packet coalescing), and servers MUST discard any client Initial UDP datagram smaller than 1,200 bytes. Furthermore, under RFC 9000 Section 8.1, prior to validating the client's address (via a Retry token or receipt of a client Handshake packet), a server MUST NOT send more than 3 times (3x) as many bytes as it has received from that client address.
3. Cryptographic Handshake Architecture (RFC 9001 & RFC 8446): 1-RTT/0-RTT Key Schedules, CRYPTO Frames, Initial Salts, and Header Protection
Unlike TLS over TCP—where TLS records wrap application data and run over a plaintext TCP header—IETF RFC 9001 (Using TLS to Secure QUIC) inverts the layering: QUIC carries TLS 1.3 (RFC 8446) handshake messages inside QUIC CRYPTO frames (Frame Type = 0x06), while QUIC uses the keys derived by the TLS 1.3 handshake to apply AEAD encryption and Header Protection (hp) to QUIC packets themselves.
TCP + TLS vs. QUIC 1-RTT and 0-RTT Handshake Comparison
Four Encryption Levels Mapped to Three Packet Number Spaces
As defined in RFC 9001 Section 2.1 and RFC 9002 Appendix A.2, QUIC data is protected at four encryption levels that map onto three independent Packet Number Spaces (each starting at packet number 0 and incrementing monotonically):
InitialEncryption Level $\rightarrow$InitialPacket Number Space: Protects the client'sClientHelloand the server'sServerHello(carried inCRYPTOframes inside Long HeaderInitialpackets) plusACKandPADDINGframes. UsesAEAD_AES_128_GCMwith keys derived deterministically from the client's first 8-to-20-byteDestination Connection ID(client_dst_connection_id) and the version-specific 20-byteinitial_salt.0-RTTEncryption Level $\rightarrow$ApplicationDataPacket Number Space: Used by a resuming client to transmit early applicationSTREAMframes (such as an idempotent HTTP/3GETrequest) in the very first flight alongside theInitialpacket, encrypted with the TLS 1.3client_early_traffic_secretfrom a previous session'sNewSessionTicket.HandshakeEncryption Level $\rightarrow$HandshakePacket Number Space: Protects the server'sEncryptedExtensions,Certificate,CertificateVerify, andFinishedmessages, as well as the client'sFinishedmessage, using keys derived from the TLS 1.3 Diffie-Hellman (ECDHE)client_handshake_traffic_secretandserver_handshake_traffic_secret.1-RTTEncryption Level $\rightarrow$ApplicationDataPacket Number Space: Shares theApplicationDatapacket number space with0-RTTpackets. Once the TLS 1.3 handshake producesclient_application_traffic_secret_0andserver_application_traffic_secret_0, endpoints switch to 1-RTT Short Header packets and discardInitialandHandshakekeys.
Mathematical Derivation of Initial Keys & Normative RFC 9001 / RFC 9369 Test Vectors
Under RFC 9001 Section 5.2 and RFC 9369 Section 3.3, both endpoints derive the Initial packet protection keys using HKDF-Extract and TLS 1.3's HKDF-Expand-Label over SHA-256 (Hash.length = 32 bytes), where HkdfLabel prefix-prepends "tls13 " to each label:
$$\text{initial\_secret} = \text{HKDF-Extract}(\text{initial\_salt},\; \text{client\_dst\_connection\_id})$$
$$\text{client\_initial\_secret} = \text{HKDF-Expand-Label}(\text{initial\_secret},\; \texttt{"client in"},\; \texttt{""},\; 32)$$
$$\text{server\_initial\_secret} = \text{HKDF-Expand-Label}(\text{initial\_secret},\; \texttt{"server in"},\; \texttt{""},\; 32)$$
From each 32-byte directional secret, the endpoint derives its 16-byte AEAD_AES_128_GCM key, 12-byte Initialization Vector (iv), and 16-byte AES-ECB Header Protection (hp) key. Using the normative 8-byte client-chosen Destination Connection ID cid = 0x8394c8f03e515708 from RFC 9001 Appendix A.1 and RFC 9369 Appendix A.1, the exact derived hexadecimal keys are:
Derived Cryptographic Value (cid = 0x8394c8f03e515708) |
QUIC v1 (RFC 9001 Appendix A.1) | QUIC v2 (RFC 9369 Appendix A.1) |
|---|---|---|
initial_secret (32B PRK) |
7db5df06e7a69e432496adedb00851923595221596ae2ae9fb8115c1e9ed0a44 |
2062e8b3cd8d52092614b8071d0aa1fb7c2e3ac193f78b280e72d8f5751f6aba |
client_initial_secret (32B) |
c00cf151ca5be075ed0ebfb5c80323c42d6b7db67881289af4008f1f6c357aea |
14ec9d6eb9fd7af83bf5a668bc17a7e283766aade7ecd0891f70f9ff7f4bf47b |
| Client AEAD Key (16B) | 1f369613dd76d5467730efcbe3b1a22d |
8b1a0bc121284290a29e0971b5cd045d |
| Client AEAD IV (12B) | fa044b2f42a3fd3b46fb255c |
91f73e2351d8fa91660e909f |
Client Header Protection Key hp (16B) |
9f50449e04a0e810283a1e9933adedd2 |
45b95e15235d6f45a6b19cbcb0294ba9 |
server_initial_secret (32B) |
3c199828fd139efd216c155ad844cc81fb82fa8d7446fa7d78be803acdda951b |
0263db1782731bf4588e7e4d93b7463907cb8cd8200b5da55a8bd488eafc37c1 |
| Server AEAD Key (16B) | cf3a5331653c364c88f0f379b6067e37 |
82db637861d55e1d011f19ea71d5d2a7 |
| Server AEAD IV (12B) | 0ac1493ca1905853b0bba03e |
dd13c276499c0249d3310652 |
Server Header Protection Key hp (16B) |
c206b8d9b9f0f37644430b490eeaa314 |
edf6d05c83121201b436e16877593c3a |
0-RTT Replay Hardening: Early-Data: 1 and HTTP 425 Too Early (RFC 8470)
While TLS 1.3 and QUIC 0-RTT packets allow a client to send an HTTP/3 request before the server proves liveness via a fresh ECDHE exchange, 0-RTT data is not forward-secret against replay: a network adversary who captures a client's 0-RTT UDP datagram can re-inject it toward the server or another anycast PoP. Under IETF RFC 8470 (Using Early Data in HTTP) and RFC 9114 Section 10.9:
- Safe/Idempotent Requests Only: Production reverse proxies (Cloudflare, NGINX, Envoy, Caddy) MUST NOT execute non-idempotent state mutations (
POST,DELETE, financial transfers) arriving in0-RTTearly data unless backed by an atomic single-use idempotency token store. - The
Early-Data: 1Request Header (RFC 8470 Section 5.1): Any reverse proxy or CDN edge node that forwards an HTTP request upstream before the client's TLS 1.3 handshake completes MUST inject the headerEarly-Data: 1(ABNF: Early-Data = "1"), and downstream hops MUST NOT strip it. - The HTTP
425 Too EarlyStatus Code (RFC 8470 Section 5.2): When an origin server receives a request in early data (or bearingEarly-Data: 1) that cannot be safely processed under replay risk, it MUST reject the request with HTTP425 Too Early, signaling the client to automatically retry the request inside a standard 1-RTT forward-secret stream once the handshake finishes.
4. Stream Multiplexing, 62-Bit Stream ID Bitmasks, Flow Control, Connection Migration, and Unreliable QUIC Datagrams (RFC 9221)
In QUIC (RFC 9000 Section 2), streams are lightweight, independent, ordered byte-stream abstractions multiplexed inside a single connection. Because encryption and packet numbering operate at the QUIC packet layer while sequencing operates per Stream ID + Byte Offset inside STREAM frames (Frame Types 0x08..0x0f), if UDP Packet #14 (carrying STREAM data for Stream 4) is lost in transit while UDP Packet #15 (carrying STREAM data for Stream 8) arrives, the QUIC stack decrypts Packet #15 immediately and delivers Stream 8's bytes to the HTTP/3 application with zero wait time.
HTTP/3 and QUIC Independent Multiplexed Streams Without Head-of-Line Blocking
The 62-Bit Stream ID Taxonomy (RFC 9000 Section 2.1 Table 1)
Every stream is identified by a 62-bit unsigned integer ($0$ to $2^{62}-1$, encoded as a varint) that is never reused within a connection. The two least significant bits (StreamID & 0x03) encode both the initiator (Bit 0 = 0x01: 0 for Client, 1 for Server) and directionality (Bit 1 = 0x02: 0 for Bidirectional, 1 for Unidirectional):
StreamID & 0x03 |
Stream Classification (RFC 9000 Table 1) | Initial Sequence (4k + type) |
Normative Role in HTTP/3 (RFC 9114 & RFC 9204) |
|---|---|---|---|
0x00 (0b00) |
Client-Initiated, Bidirectional | 0, 4, 8, 12, 16, ... |
HTTP/3 Request Streams: each client HTTP request and its corresponding server HTTP response share one bidirectional stream (0, 4, 8, ...). |
0x01 (0b01) |
Server-Initiated, Bidirectional | 1, 5, 9, 13, 17, ... |
Not used by baseline HTTP/3 (unless negotiated by a bidirectional extension such as WebTransport). |
0x02 (0b10) |
Client-Initiated, Unidirectional | 2, 6, 10, 14, ... |
Client HTTP/3 Control Stream (0x00), Client QPACK Encoder Stream (0x02), Client QPACK Decoder Stream (0x03), plus grease streams. |
0x03 (0b11) |
Server-Initiated, Unidirectional | 3, 7, 11, 15, ... |
Server HTTP/3 Control Stream (0x00), Server QPACK Encoder Stream (0x02), Server QPACK Decoder Stream (0x03), and Server Push Streams (0x01). |
Dual-Level Credit-Based Flow Control & Seamless Connection Migration
To prevent a fast sender or a single stalled stream from exhausting receiver RAM, RFC 9000 Section 4 enforces credit-based byte limits at two levels simultaneously:
- Stream-Level Flow Control: Set initially via transport parameters (
initial_max_stream_data_bidi_local,initial_max_stream_data_bidi_remote,initial_max_stream_data_uni) and incremented dynamically viaMAX_STREAM_DATA(0x11) frames. - Connection-Level Flow Control: Caps the sum of bytes received across all streams on the connection (
initial_max_data), incremented viaMAX_DATA(0x10) frames. Stream creation concurrency is separately bounded byinitial_max_streams_bidi/initial_max_streams_uniand updated viaMAX_STREAMS(0x12for bidirectional,0x13for unidirectional) frames.
When a client's network interface changes (for example, NAT rebinding or handing off from office Wi-Fi to 5G cellular), RFC 9000 Section 9 (Connection Migration) keeps the connection alive without dropping a single stream:
- Pre-Issued Connection IDs & Stateless Reset Tokens: During or after the handshake, the server issues spare Connection IDs via
NEW_CONNECTION_ID(0x18) frames, each paired with a 16-byte (128-bit)Stateless Reset Token. When migrating to a new local IP address, the client switches to a fresh unused Connection ID so passive on-path observers cannot link the user's old Wi-Fi IP to their new cellular IP. - 64-Bit Cryptographic Path Validation (
PATH_CHALLENGE&PATH_RESPONSE): Under RFC 9000 Section 8.2, the endpoint validates the new network path by sending aPATH_CHALLENGE(Frame Type = 0x1a) containing 8 bytes (64 bits) of unpredictable random data in a UDP datagram padded to at least 1,200 bytes. The peer proves reachability at the new address by echoing the exact 8-byte payload back in aPATH_RESPONSE(Frame Type = 0x1b) frame.
Unreliable QUIC Datagrams (RFC 9221) for WebTransport, Gaming, and Real-Time Media
While standard QUIC STREAM frames guarantee ordered, reliable byte delivery via automatic retransmission, real-time audio/video packets, multiplayer game state ticks, and QUIC-based IP/VPN tunnels (MASQUE) cannot afford retransmission latency on stale frames. IETF RFC 9221 (An Unreliable Datagram Extension to QUIC) introduces unreliable application datagrams that share the same TLS 1.3 handshake, 1-RTT/0-RTT AEAD encryption, and RFC 9002 congestion controller as reliable streams:
- Transport Parameter Negotiation (
max_datagram_frame_size = 0x20): An endpoint advertises support by sending the QUIC transport parametermax_datagram_frame_size(0x20, default0= unsupported; RFC 9221 Section 3 recommends65535to accept any datagram that fits inside a QUIC packet). Sending aDATAGRAMframe when the peer advertised0(or exceeding the peer's advertised byte size) is a fatal connection error of typePROTOCOL_VIOLATION. DATAGRAMFrame Types (0x30and0x31, RFC 9221 Section 4): Takes the binary form0b0011000X. When the least significant bitLEN(0x01) is0(Frame Type = 0x30), theLengthfield is omitted and the datagram payload extends to the end of the QUIC packet. WhenLENis1(Frame Type = 0x31), a variable-length integerLengthfield precedesDatagram Data, allowing multipleDATAGRAMandSTREAMframes to be packed into a single QUIC packet.
5. HTTP/3 Framing & Control Plane Architecture (RFC 9114): Unidirectional Stream Types, Frame Registry, Reserved HTTP/2 Frames, and Error Codes
IETF RFC 9114 (HTTP/3, June 2022) maps HTTP semantics (RFC 9110) onto QUIC transport. Because QUIC already provides stream multiplexing, per-stream flow control, and encryption, HTTP/3 strips out a large percentage of HTTP/2's complex framing machinery.
Unidirectional Stream Types (0x00 to 0x03)
In HTTP/3 (RFC 9114 Section 6.2 & RFC 9204 Section 4.2), every unidirectional stream begins with a single variable-length integer identifying its Stream Type. In a production HTTP/3 connection, each endpoint opens up to three critical long-lived unidirectional streams (Control, QPACK Encoder, QPACK Decoder)—and per RFC 9114 Section 6.2.1, closing or resetting any of these critical streams MUST be treated as a fatal connection error of type H3_CLOSED_CRITICAL_STREAM (0x0104):
| Stream Type Code | Unidirectional Stream Name | Allowed Sender | Normative Specification & Lifecycle Invariants |
|---|---|---|---|
0x00 |
Control Stream | Both (1 per peer) | RFC 9114 Section 6.2.1: Each side MUST initiate exactly one Control Stream. The very first frame on the Control Stream MUST be a SETTINGS (0x04) frame; receiving any other frame first triggers H3_MISSING_SETTINGS (0x010a), and a second SETTINGS frame triggers H3_FRAME_UNEXPECTED (0x0105). |
0x01 |
Push Stream | Server only | RFC 9114 Section 6.2.2: Preceded by a Push ID varint (must be $\le$ client's MAX_PUSH_ID), followed by HEADERS and DATA frames for the pushed response. If a client initiates a 0x01 stream, the server aborts with H3_STREAM_CREATION_ERROR (0x0103). |
0x02 |
QPACK Encoder Stream | Both (1 per peer) | RFC 9204 Section 4.2: Carries unframed encoder instructions that mutate the dynamic table (Set Dynamic Table Capacity, Insert With Name Reference, Insert With Literal Name, Duplicate). |
0x03 |
QPACK Decoder Stream | Both (1 per peer) | RFC 9204 Section 4.2: Carries unframed decoder feedback instructions to the encoder (Section Acknowledgment, Stream Cancellation, Insert Count Increment). |
The HTTP/3 Frame Layout & Why HTTP/2 Frame Codes 0x02, 0x06, 0x08, 0x09 Are Forbidden
Every HTTP/3 frame (RFC 9114 Section 7.1) has a 2-field envelope consisting solely of variable-length integers:
HTTP/3 Frame {
Type (i), # 62-bit variable-length integer (1..8 bytes)
Length (i), # 62-bit variable-length integer payload byte count
Frame Payload (..), # Length bytes of type-specific payload
}Crucially, because HTTP/2 and HTTP/3 share overlapping codepoint numbers, RFC 9114 Section 7.2.8 and Section 11.2.1 (Table 2) explicitly reserve and forbid the legacy HTTP/2 frame types 0x02 (PRIORITY), 0x06 (PING), 0x08 (WINDOW_UPDATE), and 0x09 (CONTINUATION) (as well as HTTP/2 settings 0x00, 0x02, 0x03, 0x04, 0x05). In HTTP/3, keep-alives and flow control belong to the QUIC transport layer (PING and MAX_DATA/MAX_STREAM_DATA), and header blocks are never split across CONTINUATION frames because HTTP/3 HEADERS frames can be up to $2^{62}-1$ bytes long. If an endpoint receives any of those reserved HTTP/2 frame types, it MUST treat it as a connection error of type H3_FRAME_UNEXPECTED (0x0105):
| Frame Type Code | HTTP/3 Frame Name | Valid Stream Placement | RFC 9114 Section 7.2 Normative Semantics |
|---|---|---|---|
0x00 |
DATA |
Request or Push Streams | Carries HTTP request or response message body bytes. Forbidden on the Control Stream (triggers H3_FRAME_UNEXPECTED = 0x0105). |
0x01 |
HEADERS |
Request or Push Streams | Carries a single QPACK-encoded HTTP field section (request headers, `1xx` informational headers, final response headers, or trailing headers). |
0x02, 0x06, 0x08, 0x09 |
Reserved (HTTP/2 Legacy) | Forbidden everywhere | Legacy HTTP/2 PRIORITY, PING, WINDOW_UPDATE, and CONTINUATION codes. Receipt MUST trigger fatal connection error H3_FRAME_UNEXPECTED (0x0105). |
0x03 |
CANCEL_PUSH |
Control Stream (0x00) |
Requests cancellation of a server push identified by Push ID before or during Push Stream transmission. |
0x04 |
SETTINGS |
Control Stream (first frame) | Conveys key-value configuration pairs such as SETTINGS_QPACK_MAX_TABLE_CAPACITY (0x01), SETTINGS_MAX_FIELD_SECTION_SIZE (0x06), and SETTINGS_QPACK_BLOCKED_STREAMS (0x07). |
0x05 |
PUSH_PROMISE |
Request Stream (Server) | Binds a Push ID varint and a QPACK-encoded request header block to an upcoming Server Push stream. |
0x07 |
GOAWAY |
Control Stream (0x00) |
Initiates graceful connection shutdown; carries the varint Stream ID (from server) or Push ID (from client) of the first unprocessed item. |
0x0d |
MAX_PUSH_ID |
Control Stream (Client) | Sent by the client to authorize the maximum Push ID the server is permitted to use (until sent, server push is disabled). |
Mandatory Protocol Greasing (0x1f * N + 0x21)
To prevent HTTP/3 parsers from ossifying around the initial set of registered codes, RFC 9114 Sections 6.2.3, 7.2.8, 7.2.4.1, and 8.1 reserve the arithmetic progression:
$$\text{GreaseCode}(N) = \text{0x1f} \times N + \text{0x21} \quad \text{for integer } N \ge 0 \quad (\text{i.e., } \text{0x21}, \text{0x40}, \text{0x5f}, \dots, \text{0x3ffffffffffffffe})$$
across all four HTTP/3 extensibility registries (Unidirectional Stream Types, Frame Types, SETTINGS identifiers, and Error Codes). Compliant HTTP/3 stacks randomly inject grease values from 0x1f * N + 0x21 and MUST silently ignore unknown frame types, unknown settings parameters, and unknown unidirectional stream types (aborting reading of unknown unidirectional streams without raising a connection error).
Visual Deep-Dive: QUIC Protocol and HTTP/3 Architecture
The following verified technical walkthrough illustrates how QUIC packet framing, TLS 1.3 handshake integration, and HTTP/3 stream multiplexing operate on the wire:
6. QPACK Header Compression (RFC 9204): Out-of-Order Dynamic Table Synchronization, the 99-Entry Static Table, and Bounded Stream Blocking
In HTTP/2, HPACK (RFC 7541) compresses headers using a static table and a shared First-In-First-Out (FIFO) dynamic table that is mutated inline by the header blocks themselves. Because TCP guarantees that every header block arrives at the decoder in the exact order the encoder generated it, the HPACK encoder and decoder dynamic tables stay in lockstep automatically.
In HTTP/3 over QUIC, request streams arrive out of order whenever a UDP packet is dropped. If Request Stream 4 inserted "authorization: Bearer xyz" into an inline dynamic table and its UDP packet was lost, while Request Stream 8 arrived immediately referencing that dynamic index, an HPACK decoder would either fail to decompress Stream 8 or decode the wrong header entry!
How RFC 9204 QPACK Eliminates Cross-Stream Compression Deadlocks
IETF RFC 9204 (QPACK: Field Compression for HTTP/3, June 2022) decouples dynamic table mutations from HTTP request streams through three mechanisms:
- Out-of-Band Unidirectional Encoder (
0x02) and Decoder (0x03) Streams: RequestHEADERSframes (0x01) never mutate the dynamic table. All dynamic table insertions are transmitted exclusively on the unidirectional QPACK Encoder Stream (0x02), and the decoder reports which dynamic table entries have arrived viaInsert Count IncrementandSection Acknowledgmentinstructions on the QPACK Decoder Stream (0x03). - Explicit
Required Insert Count(RIC) &BasePrefix on EveryHEADERSBlock: As specified in RFC 9204 Section 4.5.1, every QPACK-encoded field section begins with a two-integer prefix: *Encoded Required Insert Count(RIC): Indicates the minimum dynamic tableInsert Countthe decoder must have received on the Encoder Stream (0x02) before thisHEADERSblock can be decoded. If theHEADERSblock references only the Static Table (or literal strings),Required Insert Count == 0(encoded as byte0x00), meaning the stream can never block waiting for the Encoder Stream! WhenRIC > 0, it is encoded modulo $2 \times \text{MaxEntries}$: $$\text{MaxEntries} = \left\lfloor \frac{\text{MaxTableCapacity}}{32} \right\rfloor, \qquad \text{WireRIC} = \bigl(\text{RIC} \bmod (2 \times \text{MaxEntries})\bigr) + 1$$ *SignBit (S, 1 bit) +Delta Base(7+ bit prefix integer): Establishes theBaseindex for relative dynamic table indexing inside the header block ($\text{Base} = \text{RIC} + \text{DeltaBase}$ when $S=0$, or $\text{Base} = \text{RIC} - \text{DeltaBase} - 1$ when $S=1$). - Non-Blocking Policy & Bounded Stream Blocking (
SETTINGS_QPACK_BLOCKED_STREAMS = 0x07): By tracking which dynamic entries the decoder has acknowledged on Stream0x03(the Known Received Count), a QPACK encoder will not reference an unacknowledged dynamic entry unless the number of potentially blocked request streams remains strictly below the peer's advertisedSETTINGS_QPACK_BLOCKED_STREAMS(0x07, default0) limit. If an encoder is configured for zero blocking (or if the peer leavesSETTINGS_QPACK_BLOCKED_STREAMS = 0), the encoder only references acknowledged dynamic entries and static entries, emitting literals for newly inserted fields so that no HTTP/3 request stream ever stalls on QPACK state.
| QPACK Parameter / Error Code | Hex Value / Default | Normative RFC 9204 Specification & Memory Accounting Rule |
|---|---|---|
| Static Table (Appendix A) | 99 entries (0..98) |
0-indexed (unlike HPACK's 1-indexed 61-entry table). Runs from Index 0 (:authority) and Index 1 (:path /) to Index 17 (:method GET), Index 20 (:method POST), Index 23 (:scheme https), Index 25 (:status 200), through Index 98 (x-frame-options: sameorigin). |
| Dynamic Entry Size Formula | $\text{len}(\text{name}) + \text{len}(\text{val}) + 32$ | RFC 9204 Section 3.2.1: Each dynamic table entry's size is its uncompressed name byte length plus value byte length plus a fixed 32-byte metadata overhead allowance. |
SETTINGS_QPACK_MAX_TABLE_CAPACITY |
0x01 (Default: 0) |
Maximum byte capacity of the decoder's dynamic table. When default 0 is kept, the encoder MUST NOT insert entries into the dynamic table. |
SETTINGS_QPACK_BLOCKED_STREAMS |
0x07 (Default: 0) |
Maximum number of concurrent request/push streams that may be blocked waiting for unreceived dynamic table insertions on Stream 0x02. |
QPACK_DECOMPRESSION_FAILED |
0x0200 |
Fatal connection error raised when the decoder fails to interpret an encoded field section (e.g., invalid static index $> 98$ or out-of-range dynamic index). |
QPACK_ENCODER_STREAM_ERROR |
0x0201 |
Fatal connection error raised when the decoder fails to interpret an encoder instruction on unidirectional stream 0x02. |
QPACK_DECODER_STREAM_ERROR |
0x0202 |
Fatal connection error raised when the encoder fails to interpret a decoder feedback instruction on unidirectional stream 0x03. |
7. QUIC Loss Detection, Congestion Control (RFC 9002), Service Discovery (Alt-Svc RFC 7838 & DNS HTTPS RRType 65 RFC 9460), and Reference Python Implementation
Because QUIC packet numbers never repeat—even when a lost STREAM or CRYPTO frame is retransmitted in a brand-new packet—IETF RFC 9002 (QUIC Loss Detection and Congestion Control) eliminates TCP's retransmission ambiguity and calculates accurate RTT samples on every acknowledgment:
Normative Loss Detection Thresholds, PTO Equation, and Initial Congestion Window (RFC 9002)
- Packet Reordering Threshold (
kPacketThreshold = 3, RFC 9002 Section 6.1.1): An unacknowledged packet sent prior to an acknowledged packetlargest_ackedin the same Packet Number Space is declared lost immediately if: $$\text{largest\_acked} - \text{packet\_number} \ge k\text{PacketThreshold} \quad (k\text{PacketThreshold} = 3)$$ - Time Reordering Threshold (
kTimeThreshold = 9/8 = 1.125,kGranularity = 1 ms, Section 6.1.2): An earlier unacknowledged packet is also declared lost once the time elapsed since it was sent reaches: $$\text{loss\_delay} = \max\Bigl(\frac{9}{8} \times \max(\text{smoothed\_rtt},\; \text{latest\_rtt}),\; 1\text{ ms}\Bigr)$$ - Probe Timeout (
PTO, Section 6.2.1 & Section 6.2.2): Before the first RTT sample is obtained, the estimator seedskInitialRtt = 333 ms. When ack-eliciting packets are in flight and not acknowledged within the expected window, the sender arms a per-space Probe Timeout timer (withmax_ack_delay = 0forInitialandHandshakespaces) that doubles ($2^{\text{pto\_count}}$) on successive expirations and transmits 1–2 probe datagrams: $$\text{PTO} = \text{smoothed\_rtt} + \max(4 \times \text{rttvar},\; 1\text{ ms}) + \text{max\_ack\_delay}$$ - Initial & Minimum Congestion Window (
kInitialWindow, Section 7.2): Accounting for UDP's 8-byte header (versus TCP's 20-byte header), QUIC initializes its slow-start congestion window to 10 timesmax_datagram_sizecapped at $\max(14720,\; 2 \times \text{max\_datagram\_size})$ bytes: $$k\text{InitialWindow} = \min\Bigl(10 \times \text{max\_datagram\_size},\; \max(14720,\; 2 \times \text{max\_datagram\_size})\Bigr)$$ At the minimum requiredmax_datagram_size = 1200bytes, $k\text{InitialWindow} = 12,000$ bytes; at standard Ethernetmax_datagram_size = 1472bytes, $k\text{InitialWindow} = 14,720$ bytes. The minimum congestion window after loss (kLossReductionFactor = 0.5) or persistent congestion ($3 \times \text{PTO}$,kPersistentCongestionThreshold = 3) iskMinimumWindow = 2 * max_datagram_size.
Zero-Round-Trip HTTP/3 Service Discovery: Alt-Svc (RFC 7838) vs. DNS HTTPS Resource Records (RFC 9460)
How does a browser or API client know that https://api.example.com:443 speaks HTTP/3 (h3) over UDP port 443 before opening a TCP connection? Production deployments combine two IETF discovery mechanisms:
- HTTP Alternative Services Header (
Alt-Svc, IETF RFC 7838): On an initial HTTP/1.1 or HTTP/2 response over TCP, the server returns: ``http Alt-Svc: h3=":443"; ma=2592000, h3-29=":443"; ma=2592000`This instructs the client to cache forma = 2,592,000seconds (30 days) that the origin is reachable via ALPN token"h3"on UDP port443`. - DNS
HTTPSandSVCBResource Records (IETF RFC 9460,RRType 65&RRType 64): To eliminate even the very first TCP connection on cold cache, operators publish an RFC 9460HTTPSDNS resource record (RRType 65) alongsideAandAAAArecords. Using the registeredSvcParamKeys(mandatory = 0,alpn = 1,no-default-alpn = 2,port = 3,ipv4hint = 4,ech = 5,ipv6hint = 6from RFC 9460 Section 14.3.2 Table 1), the client discoversalpn="h3,h2"during DNS resolution and launches a 1-RTT QUIC handshake on UDP port 443 immediately: ``dns api.example.com. 300 IN HTTPS 1 . alpn="h3,h2" ipv4hint=192.0.2.42 ipv6hint=2001:db8::42``
Production Python 3 Reference Implementation: QUIC v1/v2 HKDF Key Schedule, varint Codec, and HTTP/3 Framing
The following zero-dependency Python 3 module (quic_http3_wire_codec.py) implements the normative RFC 9000 Section 16 variable-length integer encoder/decoder, the RFC 9000 Section 2.1 Stream ID classifier, the RFC 9001 Section 5.2 / RFC 9369 Section 3.3 HKDF-Extract and HKDF-Expand-Label Initial Packet Protection key schedule (verified against the exact Appendix A.1 test vectors for 0x8394c8f03e515708), and the RFC 9114 Section 7.2.4 / RFC 9204 Section 5 HTTP/3 Control Stream + SETTINGS serializer:
#!/usr/bin/env python3
"""Normative QUIC v1 (RFC 9000/9001), QUIC v2 (RFC 9369), and HTTP/3 (RFC 9114/9204) Wire Codec."""
from __future__ import annotations
import hashlib
import hmac
import struct
from dataclasses import dataclass
# Normative 20-byte Initial Salts (RFC 9001 Section 5.2 & RFC 9369 Section 3.3.1)
QUIC_V1_VERSION = 0x00000001
QUIC_V2_VERSION = 0x6B3343CF
QUIC_V1_INITIAL_SALT = bytes.fromhex("38762cf7f55934b34d179ae6a4c80cadccbb7f0a")
QUIC_V2_INITIAL_SALT = bytes.fromhex("0dede3def700a6db819381be6e269dcbf9bd2ed9")
# Normative HTTP/3 Unidirectional Stream Types & Settings (RFC 9114 & RFC 9204)
H3_STREAM_CONTROL = 0x00
H3_STREAM_PUSH = 0x01
H3_STREAM_QPACK_ENCODER = 0x02
H3_STREAM_QPACK_DECODER = 0x03
H3_FRAME_DATA = 0x00
H3_FRAME_HEADERS = 0x01
H3_FRAME_SETTINGS = 0x04
H3_FRAME_GOAWAY = 0x07
SETTINGS_QPACK_MAX_TABLE_CAPACITY = 0x01
SETTINGS_MAX_FIELD_SECTION_SIZE = 0x06
SETTINGS_QPACK_BLOCKED_STREAMS = 0x07
def encode_quic_varint(value: int) -> bytes:
"""Encode an unsigned 62-bit integer per RFC 9000 Section 16 Table 4."""
if value < 0 or value > (1 << 62) - 1:
raise ValueError(f"QUIC varint out of 62-bit range [0, 2^62-1]: {value}")
if value <= 63:
return struct.pack("!B", value)
if value <= 16383:
return struct.pack("!H", (0b01 << 14) | value)
if value <= 1073741823:
return struct.pack("!I", (0b10 << 30) | value)
return struct.pack("!Q", (0b11 << 62) | value)
def decode_quic_varint(buf: bytes, offset: int = 0) -> tuple[int, int]:
"""Decode an RFC 9000 Section 16 variable-length integer, returning (value, next_offset)."""
first = buf[offset]
prefix = first >> 6
length = 1 << prefix
raw = int.from_bytes(buf[offset : offset + length], "big")
mask = (1 << (8 * length - 2)) - 1
return raw & mask, offset + length
def classify_stream_id(stream_id: int) -> dict[str, str | bool]:
"""Classify a 62-bit QUIC Stream ID per RFC 9000 Section 2.1 Table 1."""
if stream_id < 0 or stream_id > (1 << 62) - 1:
raise ValueError("Invalid 62-bit QUIC Stream ID")
is_server = bool(stream_id & 0x01)
is_unidirectional = bool(stream_id & 0x02)
return {
"initiator": "Server" if is_server else "Client",
"direction": "Unidirectional" if is_unidirectional else "Bidirectional",
"type_bits": f"0x{stream_id & 0x03:02x}",
}
def hkdf_extract_sha256(salt: bytes, ikm: bytes) -> bytes:
"""RFC 5869 Section 2.2 HKDF-Extract using HMAC-SHA256."""
return hmac.new(salt, ikm, hashlib.sha256).digest()
def hkdf_expand_label_sha256(secret: bytes, label: str, context: bytes, length: int) -> bytes:
"""TLS 1.3 (RFC 8446 Section 7.1) HKDF-Expand-Label over SHA-256."""
full_label = b"tls13 " + label.encode("ascii")
hkdf_label = struct.pack("!HB", length, len(full_label)) + full_label + struct.pack("!B", len(context)) + context
out = b""
t = b""
counter = 1
while len(out) < length:
t = hmac.new(secret, t + hkdf_label + bytes([counter]), hashlib.sha256).digest()
out += t
counter += 1
return out[:length]
@dataclass(frozen=True)
class QuicInitialKeys:
"""Directional AEAD_AES_128_GCM and AES-ECB Header Protection keys for QUIC Initial packets."""
initial_secret: bytes
client_initial_secret: bytes
client_key: bytes
client_iv: bytes
client_hp: bytes
server_initial_secret: bytes
server_key: bytes
server_iv: bytes
server_hp: bytes
def derive_quic_initial_keys(client_dst_cid: bytes, version: int = QUIC_V1_VERSION) -> QuicInitialKeys:
"""Derive QUIC v1 (RFC 9001 Sec 5.2) or QUIC v2 (RFC 9369 Sec 3.3) Initial protection keys."""
if version == QUIC_V1_VERSION:
salt = QUIC_V1_INITIAL_SALT
key_label, iv_label, hp_label = "quic key", "quic iv", "quic hp"
elif version == QUIC_V2_VERSION:
salt = QUIC_V2_INITIAL_SALT
key_label, iv_label, hp_label = "quicv2 key", "quicv2 iv", "quicv2 hp"
else:
raise ValueError(f"Unsupported QUIC version: 0x{version:08x}")
initial_secret = hkdf_extract_sha256(salt, client_dst_cid)
client_secret = hkdf_expand_label_sha256(initial_secret, "client in", b"", 32)
server_secret = hkdf_expand_label_sha256(initial_secret, "server in", b"", 32)
return QuicInitialKeys(
initial_secret=initial_secret,
client_initial_secret=client_secret,
client_key=hkdf_expand_label_sha256(client_secret, key_label, b"", 16),
client_iv=hkdf_expand_label_sha256(client_secret, iv_label, b"", 12),
client_hp=hkdf_expand_label_sha256(client_secret, hp_label, b"", 16),
server_initial_secret=server_secret,
server_key=hkdf_expand_label_sha256(server_secret, key_label, b"", 16),
server_iv=hkdf_expand_label_sha256(server_secret, iv_label, b"", 12),
server_hp=hkdf_expand_label_sha256(server_secret, hp_label, b"", 16),
)
def build_h3_control_stream_preface(
max_table_capacity: int = 4096,
max_field_section_size: int = 16384,
blocked_streams: int = 16,
) -> bytes:
"""Serialize the HTTP/3 unidirectional Control Stream type (0x00) + initial SETTINGS (0x04) frame."""
settings_payload = (
encode_quic_varint(SETTINGS_QPACK_MAX_TABLE_CAPACITY)
+ encode_quic_varint(max_table_capacity)
+ encode_quic_varint(SETTINGS_MAX_FIELD_SECTION_SIZE)
+ encode_quic_varint(max_field_section_size)
+ encode_quic_varint(SETTINGS_QPACK_BLOCKED_STREAMS)
+ encode_quic_varint(blocked_streams)
)
settings_frame = (
encode_quic_varint(H3_FRAME_SETTINGS)
+ encode_quic_varint(len(settings_payload))
+ settings_payload
)
return encode_quic_varint(H3_STREAM_CONTROL) + settings_frame8. Frequently Asked Questions (FAQ)
1. Why does QUIC require UDP datagrams carrying Initial packets to be padded to at least 1,200 bytes (RFC 9000 Section 14.1)? Padding client and server ack-eliciting Initial packets to at least 1,200 bytes serves two simultaneous security and reliability guarantees. First, it enforces an immediate anti-amplification defense: because the client must expend at least 1,200 bytes of upstream bandwidth on its first packet, and the server is capped by the 3x anti-amplification limit (RFC 9000 Section 8.1) prior to address validation, an attacker spoofing a victim's source IP cannot achieve a high reflection amplification factor. Second, it validates immediately during the handshake that the bidirectional network path supports QUIC's minimum required IP/UDP Path Maximum Transmission Unit (PMTU) without silent blackholing once larger application data frames are sent.
2. How does QUIC Header Protection (hp, RFC 9001 Section 5.4) work if the receiver needs the Packet Number to construct the AEAD nonce before decrypting the packet? In QUIC, the AEAD payload encryption nonce is formed by XORing the 12-byte (96-bit) directional iv with the full reconstructed 62-bit Packet Number. However, to prevent middleboxes from tracking packet numbers or ossifying on header bits, the wire Packet Number field (1 to 4 bytes) and the low bits of Byte 0 (including Packet Number Length, Reserved Bits, and Key Phase) are masked using Header Protection. To remove Header Protection first, the receiver samples 16 bytes of the packet's AEAD ciphertext starting at a fixed offset of 4 bytes after the start of the Packet Number field, encrypts that 16-byte sample with the directional Header Protection key (hp) using AES-ECB (or ChaCha20), and XORs the first 5 bytes of the resulting pseudorandom mask against Byte 0's protected bits and the 1-to-4-byte wire Packet Number. This reveals Packet Number Length and the truncated wire Packet Number, which is then expanded against largest_acked and used to decrypt and authenticate the AEAD payload.
3. Why does receiving an HTTP/2 SETTINGS_ENABLE_PUSH (0x02) or WINDOW_UPDATE (0x08) code inside an HTTP/3 connection immediately terminate the connection? In HTTP/2 (RFC 9113), settings and frame codes such as PRIORITY (0x02), PING (0x06), WINDOW_UPDATE (0x08), and CONTINUATION (0x09) were required because TCP lacked per-stream flow control and stream-aware keep-alives. In HTTP/3 (RFC 9114 Sections 7.2.8 and 7.2.4.1), those functions are handled natively by the QUIC transport layer or replaced entirely. Rather than leaving those numerical slots unassigned where a buggy dual-stack implementation might accidentally emit HTTP/2 frames onto an HTTP/3 stream, RFC 9114 explicitly reserves those codepoints and mandates that receiving them MUST trigger a fatal connection error (H3_FRAME_UNEXPECTED = 0x0105 for reserved frames, or H3_SETTINGS_ERROR = 0x0109 for reserved settings 0x00, 0x02, 0x03, 0x04, 0x05).
4. How can QPACK (RFC 9204) compress headers without ever blocking an HTTP/3 request stream if SETTINGS_QPACK_BLOCKED_STREAMS (0x07) is set to 0? When a decoder leaves SETTINGS_QPACK_BLOCKED_STREAMS (0x07) at its default value of 0, the QPACK encoder is forbidden from emitting any HEADERS block whose Required Insert Count (RIC) exceeds the encoder's Known Received Count (the highest dynamic table insertion index that the decoder has explicitly acknowledged on unidirectional Decoder Stream 0x03). In that configuration, whenever a request contains a brand-new header value, the encoder simultaneously transmits an Insert instruction on Encoder Stream 0x02 and encodes that header as a literal (or static-table reference) inside the current request's HEADERS frame so RIC <= Known Received Count. Once the decoder processes Stream 0x02 and sends an acknowledgment on Stream 0x03, subsequent requests can reference that dynamic table index with zero risk of blocking.
5. What happens when an enterprise firewall blocks UDP port 443—how do browsers and HTTP/3 clients avoid connection timeouts? Modern HTTP/3 clients implement Happy Eyeballs for QUIC / HTTP/3 (building on RFC 8305 and RFC 9460). When a client discovers HTTP/3 support via a DNS HTTPS record (RRType 65) or a cached Alt-Svc: h3=":443" entry, it initiates a QUIC Initial UDP handshake on port 443 while running a short fallback timer (typically 100–300 ms). If a stateful firewall drops UDP port 443 packets, the fallback connection race transparently completes a standard TCP + TLS 1.3 + HTTP/2 handshake in parallel without exposing a connection timeout to the user, and temporarily marks the h3 alternative service as broken for that network interface.
9. Official Specifications & Primary Sources
Every packet header layout, variable-length integer range, HKDF salt and test vector, Stream ID bitmask, HTTP/3 frame and error code, QPACK static table rule, loss recovery formula, and DNS service parameter in this guide was verified directly against the following normative IETF specifications fetched during this session:
- IETF RFC 9000 — QUIC: A UDP-Based Multiplexed and Secure Transport (May 2021): https://www.rfc-editor.org/rfc/rfc9000.txt
- IETF RFC 9001 — Using TLS to Secure QUIC (May 2021): https://www.rfc-editor.org/rfc/rfc9001.txt
- IETF RFC 9002 — QUIC Loss Detection and Congestion Control (May 2021): https://www.rfc-editor.org/rfc/rfc9002.txt
- IETF RFC 9114 — HTTP/3 (June 2022): https://www.rfc-editor.org/rfc/rfc9114.txt
- IETF RFC 9204 — QPACK: Field Compression for HTTP/3 (June 2022): https://www.rfc-editor.org/rfc/rfc9204.txt
- IETF RFC 9369 — QUIC Version 2 (May 2023): https://www.rfc-editor.org/rfc/rfc9369.txt
- IETF RFC 9221 — An Unreliable Datagram Extension to QUIC (March 2022): https://www.rfc-editor.org/rfc/rfc9221.txt
- IETF RFC 9460 — Service Binding and Parameter Specification via the DNS (
SVCBandHTTPSResource Records, November 2023): https://www.rfc-editor.org/rfc/rfc9460.txt - IETF RFC 8446 — The Transport Layer Security (TLS) Protocol Version 1.3 (August 2018): https://www.rfc-editor.org/rfc/rfc8446.txt
- IETF RFC 8470 — Using Early Data in HTTP (
Early-Data: 1&425 Too Early, September 2018): https://www.rfc-editor.org/rfc/rfc8470.txt - IETF RFC 7838 — HTTP Alternative Services (
Alt-Svc, April 2016): https://www.rfc-editor.org/rfc/rfc7838.txt