proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
HTTPCommonHeaders.template.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
15
#include <
proxygen/lib/utils/Export.h
>
16
17
namespace
proxygen
{
18
22
enum
HTTPHeaderCode
:
uint8_t
{
23
// code reserved to indicate the absence of an HTTP header
24
HTTP_HEADER_NONE
= 0,
25
// code for any HTTP header name not in the list of common headers
26
HTTP_HEADER_OTHER
= 1,
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
*/
40
%%%%%
41
42
};
43
44
const
uint8_t
HTTPHeaderCodeCommonOffset
= 2;
45
46
enum
HTTPCommonHeaderTableType
:
uint8_t
{
47
TABLE_CAMELCASE
= 0,
48
TABLE_LOWERCASE
= 1,
49
};
50
51
class
HTTPCommonHeaders
{
52
public
:
53
// Perfect hash function to match common HTTP header names
54
FB_EXPORT
static
HTTPHeaderCode
hash
(
const
char
*
name
,
size_t
len);
55
56
FB_EXPORT
inline
static
HTTPHeaderCode
hash
(
const
std::string
& name) {
57
return
hash
(name.data(), name.length());
58
}
59
60
FB_EXPORT
static
std::string
*
initHeaderNames
(
HTTPCommonHeaderTableType
type
);
61
$$$$$
62
63
static
const
std::string
*
getPointerToCommonHeaderTable
(
64
HTTPCommonHeaderTableType
type);
65
66
inline
static
const
std::string
*
getPointerToHeaderName
(
HTTPHeaderCode
code,
67
HTTPCommonHeaderTableType
type =
TABLE_CAMELCASE
) {
68
return
getPointerToCommonHeaderTable
(type) + code;
69
}
70
71
inline
static
bool
isHeaderNameFromTable
(
const
std::string
* headerName,
72
HTTPCommonHeaderTableType
type) {
73
return
getHeaderCodeFromTableCommonHeaderName
(headerName, type) >=
74
HTTPHeaderCodeCommonOffset
;
75
}
76
77
// This method supplements hash(). If dealing with string pointers, some
78
// pointing to entries in the the common header name table and some not, this
79
// method can be used in place of hash to reverse map a string from the common
80
// header name table to its HTTPHeaderCode
81
inline
static
HTTPHeaderCode
getHeaderCodeFromTableCommonHeaderName
(
82
const
std::string
* headerName,
HTTPCommonHeaderTableType
type) {
83
if
(headerName ==
nullptr
) {
84
return
HTTP_HEADER_NONE
;
85
}
else
{
86
auto
diff
= headerName -
getPointerToCommonHeaderTable
(type);
87
if
(
diff
>= HTTPHeaderCodeCommonOffset &&
diff
< (
long
)
num_header_codes
) {
88
return
static_cast<
HTTPHeaderCode
>
(
diff
);
89
}
else
{
90
return
HTTP_HEADER_OTHER
;
91
}
92
}
93
}
94
95
};
96
97
}
// proxygen
FB_EXPORT
#define FB_EXPORT
Definition:
Export.h:26
proxygen::HTTP_HEADER_OTHER
Definition:
HTTPCommonHeaders.h:26
proxygen::HTTPCommonHeaders::hash
static FB_EXPORT HTTPHeaderCode hash(const std::string &name)
Definition:
HTTPCommonHeaders.template.h:56
proxygen::HTTPCommonHeaders::initHeaderNames
static FB_EXPORT std::string * initHeaderNames(HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.cpp:349
proxygen::HTTPCommonHeaderTableType
HTTPCommonHeaderTableType
Definition:
HTTPCommonHeaders.h:137
proxygen::TABLE_CAMELCASE
Definition:
HTTPCommonHeaders.h:138
type
PskType type
Definition:
ClientProtocol.cpp:777
proxygen::HTTPCommonHeaders::getHeaderCodeFromTableCommonHeaderName
static HTTPHeaderCode getHeaderCodeFromTableCommonHeaderName(const std::string *headerName, HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.h:172
proxygen::HTTPCommonHeaders
Definition:
HTTPCommonHeaders.h:142
proxygen::HTTP_HEADER_NONE
Definition:
HTTPCommonHeaders.h:24
Export.h
name
const char * name
Definition:
http_parser.c:437
proxygen::HTTPCommonHeaders::isHeaderNameFromTable
static bool isHeaderNameFromTable(const std::string *headerName, HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.template.h:71
uint8_t
uint8_t
Definition:
ConstexprMathBenchmark.cpp:178
proxygen::HTTPCommonHeaders::getPointerToHeaderName
static const std::string * getPointerToHeaderName(HTTPHeaderCode code, HTTPCommonHeaderTableType type=TABLE_CAMELCASE)
Definition:
HTTPCommonHeaders.template.h:66
diff
uint64_t diff(uint64_t a, uint64_t b)
Definition:
FutexTest.cpp:135
proxygen::HTTPCommonHeaders::num_header_codes
static constexpr uint64_t num_header_codes
Definition:
HTTPCommonHeaders.h:152
string
const char * string
Definition:
Conv.cpp:212
proxygen::HTTPCommonHeaders::getPointerToCommonHeaderTable
static const std::string * getPointerToCommonHeaderTable(HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.cpp:369
proxygen
Definition:
ExMessageHandler.h:14
proxygen::HTTPHeaderCodeCommonOffset
const uint8_t HTTPHeaderCodeCommonOffset
Definition:
HTTPCommonHeaders.h:135
proxygen::HTTPHeaderCode
HTTPHeaderCode
Definition:
HTTPCommonHeaders.h:22
proxygen::HTTPCommonHeaders::hash
static FB_EXPORT HTTPHeaderCode hash(const char *name, size_t len)
Definition:
HTTPCommonHeaders.cpp:343
proxygen::TABLE_LOWERCASE
Definition:
HTTPCommonHeaders.h:139
proxygen
lib
http
HTTPCommonHeaders.template.h
Generated by
1.8.11