proxygen
HTTPCommonHeaders.h
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  */
10 #pragma once
11 
12 #include <cstdint>
13 #include <string>
14 
16 
17 namespace proxygen {
18 
23  // code reserved to indicate the absence of an HTTP header
25  // code for any HTTP header name not in the list of common headers
27 
28  /* the following is a placeholder for the build script to generate a list
29  * of enum values from the list in HTTPCommonHeaders.txt
30  *
31  * enum name of Some-Header is HTTP_HEADER_SOME_HEADER,
32  * so an example fragment of the generated list could be:
33  * ...
34  * HTTP_HEADER_WARNING = 65,
35  * HTTP_HEADER_WWW_AUTHENTICATE = 66,
36  * HTTP_HEADER_X_BACKEND = 67,
37  * HTTP_HEADER_X_BLOCKID = 68,
38  * ...
39  */
132 
133 };
134 
136 
140 };
141 
143  public:
144  // Perfect hash function to match common HTTP header names
145  FB_EXPORT static HTTPHeaderCode hash(const char* name, size_t len);
146 
147  FB_EXPORT inline static HTTPHeaderCode hash(const std::string& name) {
148  return hash(name.data(), name.length());
149  }
150 
152  constexpr static uint64_t num_header_codes = 94;
153 
156 
159  return getPointerToCommonHeaderTable(type) + code;
160  }
161 
162  inline static bool isHeaderNameFromTable(const std::string* headerName,
164  return getHeaderCodeFromTableCommonHeaderName(headerName, type) >=
166  }
167 
168  // This method supplements hash(). If dealing with string pointers, some
169  // pointing to entries in the the common header name table and some not, this
170  // method can be used in place of hash to reverse map a string from the common
171  // header name table to its HTTPHeaderCode
173  const std::string* headerName, HTTPCommonHeaderTableType type) {
174  if (headerName == nullptr) {
175  return HTTP_HEADER_NONE;
176  } else {
177  auto diff = headerName - getPointerToCommonHeaderTable(type);
178  if (diff >= HTTPHeaderCodeCommonOffset && diff < (long)num_header_codes) {
179  return static_cast<HTTPHeaderCode>(diff);
180  } else {
181  return HTTP_HEADER_OTHER;
182  }
183  }
184  }
185 
186 };
187 
188 } // proxygen
#define FB_EXPORT
Definition: Export.h:26
static FB_EXPORT HTTPHeaderCode hash(const std::string &name)
static FB_EXPORT std::string * initHeaderNames(HTTPCommonHeaderTableType type)
PskType type
static HTTPHeaderCode getHeaderCodeFromTableCommonHeaderName(const std::string *headerName, HTTPCommonHeaderTableType type)
const char * name
Definition: http_parser.c:437
static bool isHeaderNameFromTable(const std::string *headerName, HTTPCommonHeaderTableType type)
static const std::string * getPointerToHeaderName(HTTPHeaderCode code, HTTPCommonHeaderTableType type=TABLE_CAMELCASE)
uint64_t diff(uint64_t a, uint64_t b)
Definition: FutexTest.cpp:135
static constexpr uint64_t num_header_codes
const char * string
Definition: Conv.cpp:212
static const std::string * getPointerToCommonHeaderTable(HTTPCommonHeaderTableType type)
const uint8_t HTTPHeaderCodeCommonOffset
static FB_EXPORT HTTPHeaderCode hash(const char *name, size_t len)