// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! RFC 9204 Appendix A: QPACK's static table. //! //! Ninety-nine entries where HPACK's has sixty-one, and not a superset of it: //! the order is different, the indices are different, and several entries //! carry a value HPACK left empty. It was rebuilt from what was actually seen //! on the wire after HPACK had been deployed for years, which is why //! `:status 103` is in it and HPACK's `:authority` at index 1 is here at 0. //! //! Transcribed from the RFC rather than derived from HPACK's, because the two //! tables have no relationship beyond both being lists of field lines. An //! implementation that indexed into the wrong one would produce a request //! that decodes perfectly into the wrong fields, which is the worst shape a //! bug can have -- nothing downstream of it looks wrong. const std = @import("std"); pub const Entry = struct { name: []const u8, value: []const u8, }; /// The table. Index 0 is the first entry, unlike HPACK's, where index 0 is /// not used at all -- §3.1 of RFC 9204 indexes the static table from 0, where /// §2.3.1 of RFC 7541 indexes from 1. One off, in the direction that is easy /// to miss because both are plausible and both produce a table that looks /// right. pub const entries = [_]Entry{ .{ .name = ":authority", .value = "" }, .{ .name = ":path", .value = "/" }, .{ .name = "age", .value = "0" }, .{ .name = "content-disposition", .value = "" }, .{ .name = "content-length", .value = "0" }, .{ .name = "cookie", .value = "" }, .{ .name = "date", .value = "" }, .{ .name = "etag", .value = "" }, .{ .name = "if-modified-since", .value = "" }, .{ .name = "if-none-match", .value = "" }, .{ .name = "last-modified", .value = "" }, .{ .name = "link", .value = "" }, .{ .name = "location", .value = "" }, .{ .name = "referer", .value = "" }, .{ .name = "set-cookie", .value = "" }, .{ .name = ":method", .value = "CONNECT" }, .{ .name = ":method", .value = "DELETE" }, .{ .name = ":method", .value = "GET" }, .{ .name = ":method", .value = "HEAD" }, .{ .name = ":method", .value = "OPTIONS" }, .{ .name = ":method", .value = "POST" }, .{ .name = ":method", .value = "PUT" }, .{ .name = ":scheme", .value = "http" }, .{ .name = ":scheme", .value = "https" }, .{ .name = ":status", .value = "103" }, .{ .name = ":status", .value = "200" }, .{ .name = ":status", .value = "304" }, .{ .name = ":status", .value = "404" }, .{ .name = ":status", .value = "503" }, .{ .name = "accept", .value = "*/*" }, .{ .name = "accept", .value = "application/dns-message" }, .{ .name = "accept-encoding", .value = "gzip, deflate, br" }, .{ .name = "accept-ranges", .value = "bytes" }, .{ .name = "access-control-allow-headers", .value = "cache-control" }, .{ .name = "access-control-allow-headers", .value = "content-type" }, .{ .name = "access-control-allow-origin", .value = "*" }, .{ .name = "cache-control", .value = "max-age=0" }, .{ .name = "cache-control", .value = "max-age=2592000" }, .{ .name = "cache-control", .value = "max-age=604800" }, .{ .name = "cache-control", .value = "no-cache" }, .{ .name = "cache-control", .value = "no-store" }, .{ .name = "cache-control", .value = "public, max-age=31536000" }, .{ .name = "content-encoding", .value = "br" }, .{ .name = "content-encoding", .value = "gzip" }, .{ .name = "content-type", .value = "application/dns-message" }, .{ .name = "content-type", .value = "application/javascript" }, .{ .name = "content-type", .value = "application/json" }, .{ .name = "content-type", .value = "application/x-www-form-urlencoded" }, .{ .name = "content-type", .value = "image/gif" }, .{ .name = "content-type", .value = "image/jpeg" }, .{ .name = "content-type", .value = "image/png" }, .{ .name = "content-type", .value = "text/css" }, .{ .name = "content-type", .value = "text/html; charset=utf-8" }, .{ .name = "content-type", .value = "text/plain" }, .{ .name = "content-type", .value = "text/plain;charset=utf-8" }, .{ .name = "range", .value = "bytes=0-" }, .{ .name = "strict-transport-security", .value = "max-age=31536000" }, .{ .name = "strict-transport-security", .value = "max-age=31536000; includesubdomains" }, .{ .name = "strict-transport-security", .value = "max-age=31536000; includesubdomains; preload" }, .{ .name = "vary", .value = "accept-encoding" }, .{ .name = "vary", .value = "origin" }, .{ .name = "x-content-type-options", .value = "nosniff" }, .{ .name = "x-xss-protection", .value = "1; mode=block" }, .{ .name = ":status", .value = "100" }, .{ .name = ":status", .value = "204" }, .{ .name = ":status", .value = "206" }, .{ .name = ":status", .value = "302" }, .{ .name = ":status", .value = "400" }, .{ .name = ":status", .value = "403" }, .{ .name = ":status", .value = "421" }, .{ .name = ":status", .value = "425" }, .{ .name = ":status", .value = "500" }, .{ .name = "accept-language", .value = "" }, .{ .name = "access-control-allow-credentials", .value = "FALSE" }, .{ .name = "access-control-allow-credentials", .value = "TRUE" }, .{ .name = "access-control-allow-headers", .value = "*" }, .{ .name = "access-control-allow-methods", .value = "get" }, .{ .name = "access-control-allow-methods", .value = "get, post, options" }, .{ .name = "access-control-allow-methods", .value = "options" }, .{ .name = "access-control-expose-headers", .value = "content-length" }, .{ .name = "access-control-request-headers", .value = "content-type" }, .{ .name = "access-control-request-method", .value = "get" }, .{ .name = "access-control-request-method", .value = "post" }, .{ .name = "alt-svc", .value = "clear" }, .{ .name = "authorization", .value = "" }, .{ .name = "content-security-policy", .value = "script-src 'none'; object-src 'none'; base-uri 'none'" }, .{ .name = "early-data", .value = "1" }, .{ .name = "expect-ct", .value = "" }, .{ .name = "forwarded", .value = "" }, .{ .name = "if-range", .value = "" }, .{ .name = "origin", .value = "" }, .{ .name = "purpose", .value = "prefetch" }, .{ .name = "server", .value = "" }, .{ .name = "timing-allow-origin", .value = "*" }, .{ .name = "upgrade-insecure-requests", .value = "1" }, .{ .name = "user-agent", .value = "" }, .{ .name = "x-forwarded-for", .value = "" }, .{ .name = "x-frame-options", .value = "deny" }, .{ .name = "x-frame-options", .value = "sameorigin" }, }; /// The entry at `index`, or null when there is none. pub fn get(index: u64) ?Entry { if (index >= entries.len) return null; return entries[@intCast(index)]; } test get { try std.testing.expectEqualStrings(":method", get(17).?.name); try std.testing.expectEqualStrings("GET", get(17).?.value); try std.testing.expect(get(entries.len) == null); } /// The index of an exact name-and-value match, for an encoder. Both are /// compared exactly, so a name has to be lowercase to be found. pub fn find(name: []const u8, value: []const u8) ?u64 { for (entries, 0..) |e, i| { if (std.mem.eql(u8, e.name, name) and std.mem.eql(u8, e.value, value)) return i; } return null; } test find { try std.testing.expectEqual(@as(?u64, 25), find(":status", "200")); try std.testing.expectEqual(@as(?u64, null), find(":status", "201")); } /// The index of the first entry with this name, whatever its value -- which /// is what a literal with a name reference wants. pub fn findName(name: []const u8) ?u64 { for (entries, 0..) |e, i| { if (std.mem.eql(u8, e.name, name)) return i; } return null; } test findName { // `:status 103` is the first of the `:status` entries. try std.testing.expectEqual(@as(?u64, 24), findName(":status")); try std.testing.expectEqual(@as(?u64, null), findName("x-made-up")); } const testing = std.testing; test "RFC 9204 Appendix A: ninety-nine entries, indexed from zero" { try testing.expectEqual(@as(usize, 99), entries.len); try testing.expectEqualStrings(":authority", get(0).?.name); try testing.expectEqualStrings("", get(0).?.value); try testing.expectEqualStrings("x-frame-options", get(98).?.name); try testing.expectEqualStrings("sameorigin", get(98).?.value); try testing.expect(get(99) == null); } test "RFC 9204 Appendix A: it is not HPACK's table with more on the end" { // The two have no relationship beyond both being lists of field lines, // and an implementation that indexed into the wrong one would produce a // request that decodes perfectly into the wrong fields. // // HPACK's index 2 is `:method GET`; QPACK's is `age 0`. try testing.expectEqualStrings("age", get(2).?.name); try testing.expectEqual(@as(?u64, 17), find(":method", "GET")); // HPACK has no `:status 103` at all, because it predates RFC 8297. try testing.expectEqual(@as(?u64, 24), find(":status", "103")); } test "RFC 9204 3.1: a name-only match is what a literal with a name reference wants" { // The first entry with the name, whatever its value. try testing.expectEqual(@as(?u64, 24), findName(":status")); try testing.expectEqual(@as(?u64, 15), findName(":method")); try testing.expectEqual(@as(?u64, 22), findName(":scheme")); try testing.expect(findName("x-made-up") == null); try testing.expect(find(":status", "599") == null); } test "every name in the table is lower case" { // §4.1.1 of RFC 9114 requires field names in a field section to be lower // case, and a static table entry is a field line like any other. A // capital in this transcription would be a capital on the wire. for (entries) |e| { for (e.name) |c| try testing.expect(!std.ascii.isUpper(c)); } }