xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/qpack/qpack_static_table.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/qpack/qpack_static_table.h"
6 
7 #include "absl/base/macros.h"
8 #include "quiche/quic/platform/api/quic_logging.h"
9 
10 namespace quic {
11 
12 // The "constructor" for a QpackStaticEntry that computes the lengths at
13 // compile time.
14 #define STATIC_ENTRY(name, value) \
15   { name, ABSL_ARRAYSIZE(name) - 1, value, ABSL_ARRAYSIZE(value) - 1 }
16 
QpackStaticTableVector()17 const std::vector<QpackStaticEntry>& QpackStaticTableVector() {
18   static const auto* kQpackStaticTable = new std::vector<QpackStaticEntry>{
19       STATIC_ENTRY(":authority", ""),                                     // 0
20       STATIC_ENTRY(":path", "/"),                                         // 1
21       STATIC_ENTRY("age", "0"),                                           // 2
22       STATIC_ENTRY("content-disposition", ""),                            // 3
23       STATIC_ENTRY("content-length", "0"),                                // 4
24       STATIC_ENTRY("cookie", ""),                                         // 5
25       STATIC_ENTRY("date", ""),                                           // 6
26       STATIC_ENTRY("etag", ""),                                           // 7
27       STATIC_ENTRY("if-modified-since", ""),                              // 8
28       STATIC_ENTRY("if-none-match", ""),                                  // 9
29       STATIC_ENTRY("last-modified", ""),                                  // 10
30       STATIC_ENTRY("link", ""),                                           // 11
31       STATIC_ENTRY("location", ""),                                       // 12
32       STATIC_ENTRY("referer", ""),                                        // 13
33       STATIC_ENTRY("set-cookie", ""),                                     // 14
34       STATIC_ENTRY(":method", "CONNECT"),                                 // 15
35       STATIC_ENTRY(":method", "DELETE"),                                  // 16
36       STATIC_ENTRY(":method", "GET"),                                     // 17
37       STATIC_ENTRY(":method", "HEAD"),                                    // 18
38       STATIC_ENTRY(":method", "OPTIONS"),                                 // 19
39       STATIC_ENTRY(":method", "POST"),                                    // 20
40       STATIC_ENTRY(":method", "PUT"),                                     // 21
41       STATIC_ENTRY(":scheme", "http"),                                    // 22
42       STATIC_ENTRY(":scheme", "https"),                                   // 23
43       STATIC_ENTRY(":status", "103"),                                     // 24
44       STATIC_ENTRY(":status", "200"),                                     // 25
45       STATIC_ENTRY(":status", "304"),                                     // 26
46       STATIC_ENTRY(":status", "404"),                                     // 27
47       STATIC_ENTRY(":status", "503"),                                     // 28
48       STATIC_ENTRY("accept", "*/*"),                                      // 29
49       STATIC_ENTRY("accept", "application/dns-message"),                  // 30
50       STATIC_ENTRY("accept-encoding", "gzip, deflate, br"),               // 31
51       STATIC_ENTRY("accept-ranges", "bytes"),                             // 32
52       STATIC_ENTRY("access-control-allow-headers", "cache-control"),      // 33
53       STATIC_ENTRY("access-control-allow-headers", "content-type"),       // 35
54       STATIC_ENTRY("access-control-allow-origin", "*"),                   // 35
55       STATIC_ENTRY("cache-control", "max-age=0"),                         // 36
56       STATIC_ENTRY("cache-control", "max-age=2592000"),                   // 37
57       STATIC_ENTRY("cache-control", "max-age=604800"),                    // 38
58       STATIC_ENTRY("cache-control", "no-cache"),                          // 39
59       STATIC_ENTRY("cache-control", "no-store"),                          // 40
60       STATIC_ENTRY("cache-control", "public, max-age=31536000"),          // 41
61       STATIC_ENTRY("content-encoding", "br"),                             // 42
62       STATIC_ENTRY("content-encoding", "gzip"),                           // 43
63       STATIC_ENTRY("content-type", "application/dns-message"),            // 44
64       STATIC_ENTRY("content-type", "application/javascript"),             // 45
65       STATIC_ENTRY("content-type", "application/json"),                   // 46
66       STATIC_ENTRY("content-type", "application/x-www-form-urlencoded"),  // 47
67       STATIC_ENTRY("content-type", "image/gif"),                          // 48
68       STATIC_ENTRY("content-type", "image/jpeg"),                         // 49
69       STATIC_ENTRY("content-type", "image/png"),                          // 50
70       STATIC_ENTRY("content-type", "text/css"),                           // 51
71       STATIC_ENTRY("content-type", "text/html; charset=utf-8"),           // 52
72       STATIC_ENTRY("content-type", "text/plain"),                         // 53
73       STATIC_ENTRY("content-type", "text/plain;charset=utf-8"),           // 54
74       STATIC_ENTRY("range", "bytes=0-"),                                  // 55
75       STATIC_ENTRY("strict-transport-security", "max-age=31536000"),      // 56
76       STATIC_ENTRY("strict-transport-security",
77                    "max-age=31536000; includesubdomains"),  // 57
78       STATIC_ENTRY("strict-transport-security",
79                    "max-age=31536000; includesubdomains; preload"),        // 58
80       STATIC_ENTRY("vary", "accept-encoding"),                             // 59
81       STATIC_ENTRY("vary", "origin"),                                      // 60
82       STATIC_ENTRY("x-content-type-options", "nosniff"),                   // 61
83       STATIC_ENTRY("x-xss-protection", "1; mode=block"),                   // 62
84       STATIC_ENTRY(":status", "100"),                                      // 63
85       STATIC_ENTRY(":status", "204"),                                      // 64
86       STATIC_ENTRY(":status", "206"),                                      // 65
87       STATIC_ENTRY(":status", "302"),                                      // 66
88       STATIC_ENTRY(":status", "400"),                                      // 67
89       STATIC_ENTRY(":status", "403"),                                      // 68
90       STATIC_ENTRY(":status", "421"),                                      // 69
91       STATIC_ENTRY(":status", "425"),                                      // 70
92       STATIC_ENTRY(":status", "500"),                                      // 71
93       STATIC_ENTRY("accept-language", ""),                                 // 72
94       STATIC_ENTRY("access-control-allow-credentials", "FALSE"),           // 73
95       STATIC_ENTRY("access-control-allow-credentials", "TRUE"),            // 74
96       STATIC_ENTRY("access-control-allow-headers", "*"),                   // 75
97       STATIC_ENTRY("access-control-allow-methods", "get"),                 // 76
98       STATIC_ENTRY("access-control-allow-methods", "get, post, options"),  // 77
99       STATIC_ENTRY("access-control-allow-methods", "options"),             // 78
100       STATIC_ENTRY("access-control-expose-headers", "content-length"),     // 79
101       STATIC_ENTRY("access-control-request-headers", "content-type"),      // 80
102       STATIC_ENTRY("access-control-request-method", "get"),                // 81
103       STATIC_ENTRY("access-control-request-method", "post"),               // 82
104       STATIC_ENTRY("alt-svc", "clear"),                                    // 83
105       STATIC_ENTRY("authorization", ""),                                   // 84
106       STATIC_ENTRY(
107           "content-security-policy",
108           "script-src 'none'; object-src 'none'; base-uri 'none'"),  // 85
109       STATIC_ENTRY("early-data", "1"),                               // 86
110       STATIC_ENTRY("expect-ct", ""),                                 // 87
111       STATIC_ENTRY("forwarded", ""),                                 // 88
112       STATIC_ENTRY("if-range", ""),                                  // 89
113       STATIC_ENTRY("origin", ""),                                    // 90
114       STATIC_ENTRY("purpose", "prefetch"),                           // 91
115       STATIC_ENTRY("server", ""),                                    // 92
116       STATIC_ENTRY("timing-allow-origin", "*"),                      // 93
117       STATIC_ENTRY("upgrade-insecure-requests", "1"),                // 94
118       STATIC_ENTRY("user-agent", ""),                                // 95
119       STATIC_ENTRY("x-forwarded-for", ""),                           // 96
120       STATIC_ENTRY("x-frame-options", "deny"),                       // 97
121       STATIC_ENTRY("x-frame-options", "sameorigin"),                 // 98
122   };
123   return *kQpackStaticTable;
124 }
125 
126 #undef STATIC_ENTRY
127 
ObtainQpackStaticTable()128 const QpackStaticTable& ObtainQpackStaticTable() {
129   static const QpackStaticTable* const shared_static_table = []() {
130     auto* table = new QpackStaticTable();
131     table->Initialize(QpackStaticTableVector().data(),
132                       QpackStaticTableVector().size());
133     QUICHE_CHECK(table->IsInitialized());
134     return table;
135   }();
136   return *shared_static_table;
137 }
138 
139 }  // namespace quic
140