proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
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
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
HTTP_HEADER_ACCEPT_ENCODING
= 11,
41
HTTP_HEADER_ACCEPT_LANGUAGE
= 12,
42
HTTP_HEADER_ACCEPT_RANGES
= 13,
43
HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD
= 21,
44
HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS
= 14,
45
HTTP_HEADER_AGE
= 22,
46
HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS
= 15,
47
HTTP_HEADER_ALLOW
= 23,
48
HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS
= 16,
49
HTTP_HEADER_CONTENT_LENGTH
= 31,
50
HTTP_HEADER_ALT_SVC
= 24,
51
HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
= 17,
52
HTTP_HEADER_CONTENT_LOCATION
= 32,
53
HTTP_HEADER_AUTHORIZATION
= 25,
54
HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS
= 18,
55
HTTP_HEADER_CONTENT_MD5
= 33,
56
HTTP_HEADER_CACHE_CONTROL
= 26,
57
HTTP_HEADER_ACCESS_CONTROL_MAX_AGE
= 19,
58
HTTP_HEADER_EXPIRES
= 41,
59
HTTP_HEADER_CONTENT_RANGE
= 34,
60
HTTP_HEADER_CONNECTION
= 27,
61
HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS
= 20,
62
HTTP_HEADER_FROM
= 42,
63
HTTP_HEADER_CONTENT_TYPE
= 35,
64
HTTP_HEADER_CONTENT_DISPOSITION
= 28,
65
HTTP_HEADER_FRONT_END_HTTPS
= 43,
66
HTTP_HEADER_COOKIE
= 36,
67
HTTP_HEADER_CONTENT_ENCODING
= 29,
68
HTTP_HEADER_LAST_MODIFIED
= 51,
69
HTTP_HEADER_HOST
= 44,
70
HTTP_HEADER_DNT
= 37,
71
HTTP_HEADER_CONTENT_LANGUAGE
= 30,
72
HTTP_HEADER_LINK
= 52,
73
HTTP_HEADER_IF_MATCH
= 45,
74
HTTP_HEADER_DATE
= 38,
75
HTTP_HEADER_LOCATION
= 53,
76
HTTP_HEADER_IF_MODIFIED_SINCE
= 46,
77
HTTP_HEADER_ETAG
= 39,
78
HTTP_HEADER_RANGE
= 61,
79
HTTP_HEADER_MAX_FORWARDS
= 54,
80
HTTP_HEADER_IF_NONE_MATCH
= 47,
81
HTTP_HEADER_EXPECT
= 40,
82
HTTP_HEADER_REFERER
= 62,
83
HTTP_HEADER_ORIGIN
= 55,
84
HTTP_HEADER_IF_RANGE
= 48,
85
HTTP_HEADER_REFRESH
= 63,
86
HTTP_HEADER_P3P
= 56,
87
HTTP_HEADER_IF_UNMODIFIED_SINCE
= 49,
88
HTTP_HEADER_RETRY_AFTER
= 64,
89
HTTP_HEADER_PRAGMA
= 57,
90
HTTP_HEADER_KEEP_ALIVE
= 50,
91
HTTP_HEADER_TE
= 71,
92
HTTP_HEADER_PROXY_AUTHENTICATE
= 58,
93
HTTP_HEADER_TIMESTAMP
= 72,
94
HTTP_HEADER_SEC_TOKEN_BINDING
= 65,
95
HTTP_HEADER_PROXY_AUTHORIZATION
= 59,
96
HTTP_HEADER_TRAILER
= 73,
97
HTTP_HEADER_SEC_WEBSOCKET_ACCEPT
= 66,
98
HTTP_HEADER_PROXY_CONNECTION
= 60,
99
HTTP_HEADER_WARNING
= 81,
100
HTTP_HEADER_TRANSFER_ENCODING
= 74,
101
HTTP_HEADER_SEC_WEBSOCKET_KEY
= 67,
102
HTTP_HEADER_X_ACCEL_REDIRECT
= 82,
103
HTTP_HEADER_UPGRADE
= 75,
104
HTTP_HEADER_SERVER
= 68,
105
HTTP_HEADER_X_CONTENT_SECURITY_POLICY_REPORT_ONLY
= 83,
106
HTTP_HEADER_USER_AGENT
= 76,
107
HTTP_HEADER_SET_COOKIE
= 69,
108
HTTP_HEADER_X_UA_COMPATIBLE
= 91,
109
HTTP_HEADER_X_CONTENT_TYPE_OPTIONS
= 84,
110
HTTP_HEADER_VIP
= 77,
111
HTTP_HEADER_STRICT_TRANSPORT_SECURITY
= 70,
112
HTTP_HEADER_X_WAP_PROFILE
= 92,
113
HTTP_HEADER_X_FORWARDED_FOR
= 85,
114
HTTP_HEADER_VARY
= 78,
115
HTTP_HEADER_X_XSS_PROTECTION
= 93,
116
HTTP_HEADER_X_FORWARDED_PROTO
= 86,
117
HTTP_HEADER_VIA
= 79,
118
HTTP_HEADER_X_FRAME_OPTIONS
= 87,
119
HTTP_HEADER_WWW_AUTHENTICATE
= 80,
120
HTTP_HEADER_X_POWERED_BY
= 88,
121
HTTP_HEADER_X_REAL_IP
= 89,
122
HTTP_HEADER_X_REQUESTED_WITH
= 90,
123
HTTP_HEADER_COLON_AUTHORITY
= 2,
124
HTTP_HEADER_COLON_METHOD
= 3,
125
HTTP_HEADER_COLON_PATH
= 4,
126
HTTP_HEADER_COLON_PROTOCOL
= 5,
127
HTTP_HEADER_COLON_SCHEME
= 6,
128
HTTP_HEADER_COLON_STATUS
= 7,
129
HTTP_HEADER_ACCEPT
= 8,
130
HTTP_HEADER_ACCEPT_CHARSET
= 9,
131
HTTP_HEADER_ACCEPT_DATETIME
= 10,
132
133
};
134
135
const
uint8_t
HTTPHeaderCodeCommonOffset
= 2;
136
137
enum
HTTPCommonHeaderTableType
:
uint8_t
{
138
TABLE_CAMELCASE
= 0,
139
TABLE_LOWERCASE
= 1,
140
};
141
142
class
HTTPCommonHeaders
{
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
151
FB_EXPORT
static
std::string
*
initHeaderNames
(
HTTPCommonHeaderTableType
type
);
152
constexpr
static
uint64_t
num_header_codes
= 94;
153
154
static
const
std::string
*
getPointerToCommonHeaderTable
(
155
HTTPCommonHeaderTableType
type);
156
157
inline
static
const
std::string
*
getPointerToHeaderName
(
HTTPHeaderCode
code,
158
HTTPCommonHeaderTableType
type =
TABLE_CAMELCASE
) {
159
return
getPointerToCommonHeaderTable
(type) + code;
160
}
161
162
inline
static
bool
isHeaderNameFromTable
(
const
std::string
* headerName,
163
HTTPCommonHeaderTableType
type) {
164
return
getHeaderCodeFromTableCommonHeaderName
(headerName, type) >=
165
HTTPHeaderCodeCommonOffset
;
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
172
inline
static
HTTPHeaderCode
getHeaderCodeFromTableCommonHeaderName
(
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
FB_EXPORT
#define FB_EXPORT
Definition:
Export.h:26
proxygen::HTTP_HEADER_WARNING
Definition:
HTTPCommonHeaders.h:99
proxygen::HTTP_HEADER_UPGRADE
Definition:
HTTPCommonHeaders.h:103
proxygen::HTTP_HEADER_OTHER
Definition:
HTTPCommonHeaders.h:26
proxygen::HTTP_HEADER_ACCEPT_DATETIME
Definition:
HTTPCommonHeaders.h:131
proxygen::HTTP_HEADER_X_POWERED_BY
Definition:
HTTPCommonHeaders.h:120
proxygen::HTTPCommonHeaders::hash
static FB_EXPORT HTTPHeaderCode hash(const std::string &name)
Definition:
HTTPCommonHeaders.h:147
proxygen::HTTP_HEADER_SERVER
Definition:
HTTPCommonHeaders.h:104
proxygen::HTTP_HEADER_CONTENT_LOCATION
Definition:
HTTPCommonHeaders.h:52
proxygen::HTTP_HEADER_TRAILER
Definition:
HTTPCommonHeaders.h:96
proxygen::HTTP_HEADER_SEC_WEBSOCKET_KEY
Definition:
HTTPCommonHeaders.h:101
proxygen::HTTPCommonHeaders::initHeaderNames
static FB_EXPORT std::string * initHeaderNames(HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.cpp:349
proxygen::HTTPCommonHeaderTableType
HTTPCommonHeaderTableType
Definition:
HTTPCommonHeaders.h:137
proxygen::HTTP_HEADER_SET_COOKIE
Definition:
HTTPCommonHeaders.h:107
proxygen::HTTP_HEADER_DNT
Definition:
HTTPCommonHeaders.h:70
proxygen::HTTP_HEADER_ACCEPT_ENCODING
Definition:
HTTPCommonHeaders.h:40
proxygen::HTTP_HEADER_VIP
Definition:
HTTPCommonHeaders.h:110
proxygen::HTTP_HEADER_ALLOW
Definition:
HTTPCommonHeaders.h:47
proxygen::TABLE_CAMELCASE
Definition:
HTTPCommonHeaders.h:138
type
PskType type
Definition:
ClientProtocol.cpp:777
proxygen::HTTP_HEADER_COLON_SCHEME
Definition:
HTTPCommonHeaders.h:127
proxygen::HTTP_HEADER_FROM
Definition:
HTTPCommonHeaders.h:62
proxygen::HTTP_HEADER_PRAGMA
Definition:
HTTPCommonHeaders.h:89
proxygen::HTTP_HEADER_IF_MATCH
Definition:
HTTPCommonHeaders.h:73
proxygen::HTTP_HEADER_CONNECTION
Definition:
HTTPCommonHeaders.h:60
proxygen::HTTP_HEADER_COLON_METHOD
Definition:
HTTPCommonHeaders.h:124
proxygen::HTTP_HEADER_COLON_PATH
Definition:
HTTPCommonHeaders.h:125
proxygen::HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS
Definition:
HTTPCommonHeaders.h:48
proxygen::HTTP_HEADER_ACCEPT_RANGES
Definition:
HTTPCommonHeaders.h:42
proxygen::HTTP_HEADER_CACHE_CONTROL
Definition:
HTTPCommonHeaders.h:56
proxygen::HTTP_HEADER_IF_MODIFIED_SINCE
Definition:
HTTPCommonHeaders.h:76
proxygen::HTTP_HEADER_PROXY_AUTHENTICATE
Definition:
HTTPCommonHeaders.h:92
proxygen::HTTP_HEADER_CONTENT_ENCODING
Definition:
HTTPCommonHeaders.h:67
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
proxygen::HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS
Definition:
HTTPCommonHeaders.h:46
proxygen::HTTP_HEADER_ACCEPT_CHARSET
Definition:
HTTPCommonHeaders.h:130
proxygen::HTTP_HEADER_X_REQUESTED_WITH
Definition:
HTTPCommonHeaders.h:122
proxygen::HTTP_HEADER_CONTENT_RANGE
Definition:
HTTPCommonHeaders.h:59
proxygen::HTTP_HEADER_IF_NONE_MATCH
Definition:
HTTPCommonHeaders.h:80
proxygen::HTTP_HEADER_CONTENT_TYPE
Definition:
HTTPCommonHeaders.h:63
proxygen::HTTP_HEADER_RANGE
Definition:
HTTPCommonHeaders.h:78
proxygen::HTTP_HEADER_X_UA_COMPATIBLE
Definition:
HTTPCommonHeaders.h:108
proxygen::HTTP_HEADER_STRICT_TRANSPORT_SECURITY
Definition:
HTTPCommonHeaders.h:111
proxygen::HTTP_HEADER_PROXY_AUTHORIZATION
Definition:
HTTPCommonHeaders.h:95
proxygen::HTTP_HEADER_ORIGIN
Definition:
HTTPCommonHeaders.h:83
proxygen::HTTP_HEADER_SEC_WEBSOCKET_ACCEPT
Definition:
HTTPCommonHeaders.h:97
Export.h
name
const char * name
Definition:
http_parser.c:437
proxygen::HTTP_HEADER_TRANSFER_ENCODING
Definition:
HTTPCommonHeaders.h:100
proxygen::HTTP_HEADER_X_ACCEL_REDIRECT
Definition:
HTTPCommonHeaders.h:102
proxygen::HTTP_HEADER_RETRY_AFTER
Definition:
HTTPCommonHeaders.h:88
proxygen::HTTP_HEADER_X_FORWARDED_FOR
Definition:
HTTPCommonHeaders.h:113
proxygen::HTTP_HEADER_ACCESS_CONTROL_MAX_AGE
Definition:
HTTPCommonHeaders.h:57
proxygen::HTTP_HEADER_REFERER
Definition:
HTTPCommonHeaders.h:82
proxygen::HTTP_HEADER_EXPIRES
Definition:
HTTPCommonHeaders.h:58
proxygen::HTTP_HEADER_CONTENT_LENGTH
Definition:
HTTPCommonHeaders.h:49
proxygen::HTTPCommonHeaders::isHeaderNameFromTable
static bool isHeaderNameFromTable(const std::string *headerName, HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.h:162
proxygen::HTTP_HEADER_DATE
Definition:
HTTPCommonHeaders.h:74
proxygen::HTTP_HEADER_X_WAP_PROFILE
Definition:
HTTPCommonHeaders.h:112
uint8_t
uint8_t
Definition:
ConstexprMathBenchmark.cpp:178
proxygen::HTTP_HEADER_MAX_FORWARDS
Definition:
HTTPCommonHeaders.h:79
proxygen::HTTP_HEADER_LOCATION
Definition:
HTTPCommonHeaders.h:75
proxygen::HTTP_HEADER_IF_UNMODIFIED_SINCE
Definition:
HTTPCommonHeaders.h:87
proxygen::HTTP_HEADER_TIMESTAMP
Definition:
HTTPCommonHeaders.h:93
proxygen::HTTP_HEADER_AGE
Definition:
HTTPCommonHeaders.h:45
proxygen::HTTP_HEADER_COLON_PROTOCOL
Definition:
HTTPCommonHeaders.h:126
proxygen::HTTP_HEADER_SEC_TOKEN_BINDING
Definition:
HTTPCommonHeaders.h:94
proxygen::HTTP_HEADER_X_FRAME_OPTIONS
Definition:
HTTPCommonHeaders.h:118
proxygen::HTTP_HEADER_VIA
Definition:
HTTPCommonHeaders.h:117
proxygen::HTTPCommonHeaders::getPointerToHeaderName
static const std::string * getPointerToHeaderName(HTTPHeaderCode code, HTTPCommonHeaderTableType type=TABLE_CAMELCASE)
Definition:
HTTPCommonHeaders.h:157
proxygen::HTTP_HEADER_X_CONTENT_TYPE_OPTIONS
Definition:
HTTPCommonHeaders.h:109
proxygen::HTTP_HEADER_ACCEPT
Definition:
HTTPCommonHeaders.h:129
proxygen::HTTP_HEADER_X_FORWARDED_PROTO
Definition:
HTTPCommonHeaders.h:116
proxygen::HTTP_HEADER_X_XSS_PROTECTION
Definition:
HTTPCommonHeaders.h:115
proxygen::HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD
Definition:
HTTPCommonHeaders.h:43
proxygen::HTTP_HEADER_FRONT_END_HTTPS
Definition:
HTTPCommonHeaders.h:65
proxygen::HTTP_HEADER_LAST_MODIFIED
Definition:
HTTPCommonHeaders.h:68
diff
uint64_t diff(uint64_t a, uint64_t b)
Definition:
FutexTest.cpp:135
proxygen::HTTP_HEADER_TE
Definition:
HTTPCommonHeaders.h:91
proxygen::HTTP_HEADER_USER_AGENT
Definition:
HTTPCommonHeaders.h:106
proxygen::HTTP_HEADER_AUTHORIZATION
Definition:
HTTPCommonHeaders.h:53
proxygen::HTTPCommonHeaders::num_header_codes
static constexpr uint64_t num_header_codes
Definition:
HTTPCommonHeaders.h:152
proxygen::HTTP_HEADER_ETAG
Definition:
HTTPCommonHeaders.h:77
proxygen::HTTP_HEADER_X_REAL_IP
Definition:
HTTPCommonHeaders.h:121
proxygen::HTTP_HEADER_IF_RANGE
Definition:
HTTPCommonHeaders.h:84
proxygen::HTTP_HEADER_HOST
Definition:
HTTPCommonHeaders.h:69
string
const char * string
Definition:
Conv.cpp:212
proxygen::HTTPCommonHeaders::getPointerToCommonHeaderTable
static const std::string * getPointerToCommonHeaderTable(HTTPCommonHeaderTableType type)
Definition:
HTTPCommonHeaders.cpp:369
proxygen::HTTP_HEADER_VARY
Definition:
HTTPCommonHeaders.h:114
uint64_t
uint64_t
Definition:
ConstexprMathBenchmark.cpp:190
proxygen::HTTP_HEADER_PROXY_CONNECTION
Definition:
HTTPCommonHeaders.h:98
proxygen::HTTP_HEADER_CONTENT_DISPOSITION
Definition:
HTTPCommonHeaders.h:64
proxygen
Definition:
ExMessageHandler.h:14
proxygen::HTTPHeaderCodeCommonOffset
const uint8_t HTTPHeaderCodeCommonOffset
Definition:
HTTPCommonHeaders.h:135
proxygen::HTTPHeaderCode
HTTPHeaderCode
Definition:
HTTPCommonHeaders.h:22
proxygen::HTTP_HEADER_LINK
Definition:
HTTPCommonHeaders.h:72
proxygen::HTTP_HEADER_ACCEPT_LANGUAGE
Definition:
HTTPCommonHeaders.h:41
proxygen::HTTP_HEADER_ALT_SVC
Definition:
HTTPCommonHeaders.h:50
proxygen::HTTP_HEADER_COLON_STATUS
Definition:
HTTPCommonHeaders.h:128
proxygen::HTTPCommonHeaders::hash
static FB_EXPORT HTTPHeaderCode hash(const char *name, size_t len)
Definition:
HTTPCommonHeaders.cpp:343
proxygen::HTTP_HEADER_COLON_AUTHORITY
Definition:
HTTPCommonHeaders.h:123
proxygen::HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS
Definition:
HTTPCommonHeaders.h:54
proxygen::HTTP_HEADER_CONTENT_MD5
Definition:
HTTPCommonHeaders.h:55
proxygen::HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS
Definition:
HTTPCommonHeaders.h:61
proxygen::HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
Definition:
HTTPCommonHeaders.h:51
proxygen::HTTP_HEADER_REFRESH
Definition:
HTTPCommonHeaders.h:85
proxygen::HTTP_HEADER_COOKIE
Definition:
HTTPCommonHeaders.h:66
proxygen::TABLE_LOWERCASE
Definition:
HTTPCommonHeaders.h:139
proxygen::HTTP_HEADER_X_CONTENT_SECURITY_POLICY_REPORT_ONLY
Definition:
HTTPCommonHeaders.h:105
proxygen::HTTP_HEADER_KEEP_ALIVE
Definition:
HTTPCommonHeaders.h:90
proxygen::HTTP_HEADER_P3P
Definition:
HTTPCommonHeaders.h:86
proxygen::HTTP_HEADER_WWW_AUTHENTICATE
Definition:
HTTPCommonHeaders.h:119
proxygen::HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS
Definition:
HTTPCommonHeaders.h:44
proxygen::HTTP_HEADER_CONTENT_LANGUAGE
Definition:
HTTPCommonHeaders.h:71
proxygen::HTTP_HEADER_EXPECT
Definition:
HTTPCommonHeaders.h:81
proxygen
lib
http
HTTPCommonHeaders.h
Generated by
1.8.11