proxygen
HPACKContext.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 namespace proxygen {
13 
15  table_(tableSize) {
16 }
17 
19  // First consult the static header table if applicable
20  // Applicability is determined by the following guided optimizations:
21  // 1) The set of CommonHeaders includes all StaticTable headers and so we can
22  // quickly conclude that we need not check the StaticTable
23  // for non-CommonHeaders
24  // 2) The StaticTable only contains non empty values for a very small subset
25  // of header names. As getIndex is only meaingful if both name and value
26  // match, we know that if our header has a value and is not part of the very
27  // small subset of header names, there is no point consulting the StaticTable
28  bool consultStaticTable = false;
29  if (header.value.empty()) {
30  consultStaticTable = header.name.isCommonHeader();
31  } else {
32  consultStaticTable =
34  header.name.getHeaderCode());
35  }
36  if (consultStaticTable) {
37  uint32_t staticIndex = getStaticTable().getIndex(header);
38  if (staticIndex) {
39  return staticToGlobalIndex(staticIndex);
40  }
41  }
42 
43  // Else check the dynamic table
44  uint32_t dynamicIndex = table_.getIndex(header);
45  if (dynamicIndex) {
46  return dynamicToGlobalIndex(dynamicIndex);
47  } else {
48  return dynamicIndex;
49  }
50 }
51 
53  uint32_t index = getStaticTable().nameIndex(headerName);
54  if (index) {
55  return staticToGlobalIndex(index);
56  }
57  index = table_.nameIndex(headerName);
58  if (index) {
59  return dynamicToGlobalIndex(index);
60  }
61  return 0;
62 }
63 
64 bool HPACKContext::isStatic(uint32_t index) const {
65  return index <= getStaticTable().size();
66 }
67 
69  if (isStatic(index)) {
71  }
72  return table_.getHeader(globalToDynamicIndex(index));
73 }
74 
76  std::vector<HPACKHeader>& headers) {
77  for (auto& header: headers) {
78  table_.add(std::move(header));
79  }
80 }
81 
82 void HPACKContext::describe(std::ostream& os) const {
83  os << table_;
84 }
85 
86 std::ostream& operator<<(std::ostream& os, const HPACKContext& context) {
87  context.describe(os);
88  return os;
89 }
90 
91 }
uint32_t globalToStaticIndex(uint32_t index) const
Definition: HPACKContext.h:76
bool empty() const
Definition: FBString.h:1372
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
void seedHeaderTable(std::vector< HPACKHeader > &headers)
HTTPHeaderCode getHeaderCode() const
void describe(std::ostream &os) const
context
Definition: CMakeCache.txt:563
uint32_t nameIndex(const HPACKHeaderName &headerName) const
static bool isHeaderCodeInTableWithNonEmptyValue(HTTPHeaderCode headerCode)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const HPACKHeader & getHeader(uint32_t index) const
Definition: HeaderTable.cpp:93
uint32_t staticToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:82
const HPACKHeader & getHeader(uint32_t index)
uint32_t getIndex(const HPACKHeader &header) const
const StaticHeaderTable & getStaticTable() const
Definition: HPACKContext.h:69
HPACKHeaderName name
Definition: HPACKHeader.h:82
uint32_t nameIndex(const HPACKHeaderName &headerName) const
Definition: HeaderTable.cpp:88
folly::fbstring value
Definition: HPACKHeader.h:83
bool isStatic(uint32_t index) const
uint32_t size() const
Definition: HeaderTable.h:105
HPACKContext(uint32_t tableSize)
uint32_t getIndex(const HPACKHeader &header) const
Definition: HeaderTable.cpp:63
uint32_t globalToDynamicIndex(uint32_t index) const
Definition: HPACKContext.h:73
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33
uint32_t dynamicToGlobalIndex(uint32_t index) const
Definition: HPACKContext.h:79