proxygen
StaticHeaderTable.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
11 
12 #include <folly/Indestructible.h>
13 
14 #include <glog/logging.h>
15 #include <list>
16 
17 using std::list;
18 using std::string;
19 using std::vector;
20 
21 namespace proxygen {
22 
23 // Array of static header table entires pair
24 // Note: if updating this table (should never have to but whatever), update
25 // isHeaderNameInTableWithNonEmptyValue as well
26 const char* s_tableEntries[][2] = {
27  {":authority", ""},
28  {":method", "GET"},
29  {":method", "POST"},
30  {":path", "/"},
31  {":path", "/index.html"},
32  {":scheme", "http"},
33  {":scheme", "https"},
34  {":status", "200"},
35  {":status", "204"},
36  {":status", "206"},
37  {":status", "304"},
38  {":status", "400"},
39  {":status", "404"},
40  {":status", "500"},
41  {"accept-charset", ""},
42  {"accept-encoding", "gzip, deflate"},
43  {"accept-language", ""},
44  {"accept-ranges", ""},
45  {"accept", ""},
46  {"access-control-allow-origin", ""},
47  {"age", ""},
48  {"allow", ""},
49  {"authorization", ""},
50  {"cache-control", ""},
51  {"content-disposition", ""},
52  {"content-encoding", ""},
53  {"content-language", ""},
54  {"content-length", ""},
55  {"content-location", ""},
56  {"content-range", ""},
57  {"content-type", ""},
58  {"cookie", ""},
59  {"date", ""},
60  {"etag", ""},
61  {"expect", ""},
62  {"expires", ""},
63  {"from", ""},
64  {"host", ""},
65  {"if-match", ""},
66  {"if-modified-since", ""},
67  {"if-none-match", ""},
68  {"if-range", ""},
69  {"if-unmodified-since", ""},
70  {"last-modified", ""},
71  {"link", ""},
72  {"location", ""},
73  {"max-forwards", ""},
74  {"proxy-authenticate", ""},
75  {"proxy-authorization", ""},
76  {"range", ""},
77  {"referer", ""},
78  {"refresh", ""},
79  {"retry-after", ""},
80  {"server", ""},
81  {"set-cookie", ""},
82  {"strict-transport-security", ""},
83  {"transfer-encoding", ""},
84  {"user-agent", ""},
85  {"vary", ""},
86  {"via", ""},
87  {"www-authenticate", ""}
88 };
89 
90 const int kEntriesSize = sizeof(s_tableEntries) / (2 * sizeof(const char*));
91 
93  HTTPHeaderCode headerCode) {
94  switch(headerCode) {
100  return true;
101 
102  default:
103  return false;
104  }
105 }
106 
108  const char* entries[][2],
109  int size)
110  : HeaderTable(0) {
111  // calculate the size
112  list<HPACKHeader> hlist;
113  uint32_t byteCount = 0;
114  for (int i = 0; i < size; ++i) {
115  hlist.push_back(HPACKHeader(entries[i][0], entries[i][1]));
116  byteCount += hlist.back().bytes();
117  }
118  // initialize with a capacity that will exactly fit the static headers
119  init(byteCount);
120  hlist.reverse();
121  for (auto& header : hlist) {
122  add(std::move(header));
123  }
124 }
125 
127  static const folly::Indestructible<StaticHeaderTable> table(
128  s_tableEntries, kEntriesSize);
129  return *table;
130 }
131 
132 }
StaticHeaderTable(const char *entries[][2], int size)
const int kEntriesSize
static bool isHeaderCodeInTableWithNonEmptyValue(HTTPHeaderCode headerCode)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const char * s_tableEntries[][2]
static const StaticHeaderTable & get()
Encoder::MutableCompressedList list
void init(uint32_t capacityVal)
Definition: HeaderTable.cpp:20
const char * string
Definition: Conv.cpp:212
uint32_t size() const
Definition: HeaderTable.h:105
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33