-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
headers.h
343 lines (305 loc) · 13.7 KB
/
headers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#pragma once
#include <string>
#include "envoy/http/header_map.h"
#include "source/common/singleton/const_singleton.h"
#include "source/common/singleton/threadsafe_singleton.h"
namespace Envoy {
namespace Http {
// This class allows early override of the x-envoy prefix from bootstrap config,
// so that servers can configure their own x-custom-string prefix.
//
// Once the HeaderValues const singleton has been created, changing the prefix
// is disallowed. Essentially this is write-once then read-only.
class PrefixValue {
public:
const char* prefix() {
absl::WriterMutexLock lock(&m_);
read_ = true;
return prefix_.c_str();
}
// The char* prefix is used directly, so must be available for the interval where prefix() may be
// called.
void setPrefix(const char* prefix) {
absl::WriterMutexLock lock(&m_);
// The check for unchanged string is purely for integration tests - this
// should not happen in production.
RELEASE_ASSERT(!read_ || prefix_ == std::string(prefix),
"Attempting to change the header prefix after it has been used!");
if (!read_) {
prefix_ = prefix;
}
}
private:
absl::Mutex m_;
bool read_ = false;
std::string prefix_ = "x-envoy";
};
/**
* These are headers that are used in extension custom O(1) header registration. These headers
* *must* not contain any prefix override headers, as static init order requires that HeaderValues
* be instantiated for the first time after bootstrap is loaded and before the header maps are
* finalized.
*/
class CustomHeaderValues {
public:
const LowerCaseString Accept{"accept"};
const LowerCaseString AcceptEncoding{"accept-encoding"};
const LowerCaseString AccessControlRequestMethod{"access-control-request-method"};
const LowerCaseString AccessControlAllowOrigin{"access-control-allow-origin"};
const LowerCaseString AccessControlAllowHeaders{"access-control-allow-headers"};
const LowerCaseString AccessControlAllowMethods{"access-control-allow-methods"};
const LowerCaseString AccessControlExposeHeaders{"access-control-expose-headers"};
const LowerCaseString AccessControlMaxAge{"access-control-max-age"};
const LowerCaseString AccessControlAllowCredentials{"access-control-allow-credentials"};
const LowerCaseString Age{"age"};
const LowerCaseString AltSvc{"alt-svc"};
const LowerCaseString Authentication{"authentication"};
const LowerCaseString Authorization{"authorization"};
const LowerCaseString CacheControl{"cache-control"};
const LowerCaseString CdnLoop{"cdn-loop"};
const LowerCaseString ContentEncoding{"content-encoding"};
const LowerCaseString Etag{"etag"};
const LowerCaseString Expires{"expires"};
const LowerCaseString GrpcAcceptEncoding{"grpc-accept-encoding"};
const LowerCaseString IfMatch{"if-match"};
const LowerCaseString IfNoneMatch{"if-none-match"};
const LowerCaseString IfModifiedSince{"if-modified-since"};
const LowerCaseString IfUnmodifiedSince{"if-unmodified-since"};
const LowerCaseString IfRange{"if-range"};
const LowerCaseString LastModified{"last-modified"};
const LowerCaseString Origin{"origin"};
const LowerCaseString OtSpanContext{"x-ot-span-context"};
const LowerCaseString Pragma{"pragma"};
const LowerCaseString Referer{"referer"};
const LowerCaseString Vary{"vary"};
struct {
const std::string Gzip{"gzip"};
const std::string Identity{"identity"};
const std::string Wildcard{"*"};
} AcceptEncodingValues;
struct {
const std::string All{"*"};
} AccessControlAllowOriginValue;
struct {
const std::string NoCache{"no-cache"};
const std::string NoCacheMaxAge0{"no-cache, max-age=0"};
const std::string NoTransform{"no-transform"};
const std::string Private{"private"};
} CacheControlValues;
struct {
const std::string Brotli{"br"};
const std::string Gzip{"gzip"};
} ContentEncodingValues;
struct {
const std::string True{"true"};
} CORSValues;
struct {
const std::string Default{"identity"};
} GrpcAcceptEncodingValues;
struct {
const std::string AcceptEncoding{"Accept-Encoding"};
const std::string Wildcard{"*"};
} VaryValues;
};
using CustomHeaders = ConstSingleton<CustomHeaderValues>;
/**
* Constant HTTP headers and values. All lower case. This group of headers can contain prefix
* override headers.
*/
class HeaderValues {
public:
const char* prefix() const { return ThreadSafeSingleton<PrefixValue>::get().prefix(); }
const LowerCaseString ProxyAuthenticate{"proxy-authenticate"};
const LowerCaseString ProxyAuthorization{"proxy-authorization"};
const LowerCaseString ClientTraceId{"x-client-trace-id"};
const LowerCaseString Connection{"connection"};
const LowerCaseString ContentLength{"content-length"};
const LowerCaseString ContentRange{"content-range"};
const LowerCaseString ContentType{"content-type"};
const LowerCaseString Cookie{"cookie"};
const LowerCaseString Date{"date"};
const LowerCaseString EnvoyAttemptCount{absl::StrCat(prefix(), "-attempt-count")};
const LowerCaseString EnvoyCluster{absl::StrCat(prefix(), "-cluster")};
const LowerCaseString EnvoyDegraded{absl::StrCat(prefix(), "-degraded")};
const LowerCaseString EnvoyDownstreamServiceCluster{
absl::StrCat(prefix(), "-downstream-service-cluster")};
const LowerCaseString EnvoyDownstreamServiceNode{
absl::StrCat(prefix(), "-downstream-service-node")};
const LowerCaseString EnvoyExternalAddress{absl::StrCat(prefix(), "-external-address")};
const LowerCaseString EnvoyForceTrace{absl::StrCat(prefix(), "-force-trace")};
const LowerCaseString EnvoyHedgeOnPerTryTimeout{
absl::StrCat(prefix(), "-hedge-on-per-try-timeout")};
const LowerCaseString EnvoyImmediateHealthCheckFail{
absl::StrCat(prefix(), "-immediate-health-check-fail")};
const LowerCaseString EnvoyOriginalUrl{absl::StrCat(prefix(), "-original-url")};
const LowerCaseString EnvoyInternalRequest{absl::StrCat(prefix(), "-internal")};
// TODO(mattklein123): EnvoyIpTags should be a custom header registered with the IP tagging
// filter. We need to figure out if we can remove this header from the set of headers that
// participate in prefix overrides.
const LowerCaseString EnvoyIpTags{absl::StrCat(prefix(), "-ip-tags")};
const LowerCaseString EnvoyMaxRetries{absl::StrCat(prefix(), "-max-retries")};
const LowerCaseString EnvoyNotForwarded{absl::StrCat(prefix(), "-not-forwarded")};
const LowerCaseString EnvoyOriginalDstHost{absl::StrCat(prefix(), "-original-dst-host")};
const LowerCaseString EnvoyOriginalMethod{absl::StrCat(prefix(), "-original-method")};
const LowerCaseString EnvoyOriginalPath{absl::StrCat(prefix(), "-original-path")};
const LowerCaseString EnvoyOverloaded{absl::StrCat(prefix(), "-overloaded")};
const LowerCaseString EnvoyRateLimited{absl::StrCat(prefix(), "-ratelimited")};
const LowerCaseString EnvoyRetryOn{absl::StrCat(prefix(), "-retry-on")};
const LowerCaseString EnvoyRetryGrpcOn{absl::StrCat(prefix(), "-retry-grpc-on")};
const LowerCaseString EnvoyRetriableStatusCodes{
absl::StrCat(prefix(), "-retriable-status-codes")};
const LowerCaseString EnvoyRetriableHeaderNames{
absl::StrCat(prefix(), "-retriable-header-names")};
const LowerCaseString EnvoyUpstreamAltStatName{absl::StrCat(prefix(), "-upstream-alt-stat-name")};
const LowerCaseString EnvoyUpstreamCanary{absl::StrCat(prefix(), "-upstream-canary")};
const LowerCaseString EnvoyUpstreamHostAddress{absl::StrCat(prefix(), "-upstream-host-address")};
const LowerCaseString EnvoyUpstreamHostname{absl::StrCat(prefix(), "-upstream-hostname")};
const LowerCaseString EnvoyUpstreamRequestTimeoutAltResponse{
absl::StrCat(prefix(), "-upstream-rq-timeout-alt-response")};
const LowerCaseString EnvoyUpstreamRequestTimeoutMs{
absl::StrCat(prefix(), "-upstream-rq-timeout-ms")};
const LowerCaseString EnvoyUpstreamRequestPerTryTimeoutMs{
absl::StrCat(prefix(), "-upstream-rq-per-try-timeout-ms")};
const LowerCaseString EnvoyExpectedRequestTimeoutMs{
absl::StrCat(prefix(), "-expected-rq-timeout-ms")};
const LowerCaseString EnvoyUpstreamServiceTime{absl::StrCat(prefix(), "-upstream-service-time")};
const LowerCaseString EnvoyUpstreamHealthCheckedCluster{
absl::StrCat(prefix(), "-upstream-healthchecked-cluster")};
const LowerCaseString EnvoyUpstreamStreamDurationMs{
absl::StrCat(prefix(), "-upstream-stream-duration-ms")};
const LowerCaseString EnvoyDecoratorOperation{absl::StrCat(prefix(), "-decorator-operation")};
const LowerCaseString Expect{"expect"};
const LowerCaseString ForwardedClientCert{"x-forwarded-client-cert"};
const LowerCaseString ForwardedFor{"x-forwarded-for"};
const LowerCaseString ForwardedHost{"x-forwarded-host"};
const LowerCaseString ForwardedProto{"x-forwarded-proto"};
const LowerCaseString GrpcMessage{"grpc-message"};
const LowerCaseString GrpcStatus{"grpc-status"};
const LowerCaseString GrpcTimeout{"grpc-timeout"};
const LowerCaseString GrpcStatusDetailsBin{"grpc-status-details-bin"};
const LowerCaseString Host{":authority"};
const LowerCaseString HostLegacy{"host"};
const LowerCaseString Http2Settings{"http2-settings"};
const LowerCaseString KeepAlive{"keep-alive"};
const LowerCaseString Location{"location"};
const LowerCaseString Method{":method"};
const LowerCaseString Path{":path"};
const LowerCaseString Protocol{":protocol"};
const LowerCaseString ProxyConnection{"proxy-connection"};
const LowerCaseString Range{"range"};
const LowerCaseString RequestId{"x-request-id"};
const LowerCaseString Scheme{":scheme"};
const LowerCaseString Server{"server"};
const LowerCaseString SetCookie{"set-cookie"};
const LowerCaseString Status{":status"};
const LowerCaseString TransferEncoding{"transfer-encoding"};
const LowerCaseString TE{"te"};
const LowerCaseString Upgrade{"upgrade"};
const LowerCaseString UserAgent{"user-agent"};
const LowerCaseString Via{"via"};
const LowerCaseString WWWAuthenticate{"www-authenticate"};
const LowerCaseString XContentTypeOptions{"x-content-type-options"};
const LowerCaseString XSquashDebug{"x-squash-debug"};
struct {
const std::string Close{"close"};
const std::string Http2Settings{"http2-settings"};
const std::string KeepAlive{"keep-alive"};
const std::string Upgrade{"upgrade"};
} ConnectionValues;
struct {
const std::string H2c{"h2c"};
const std::string WebSocket{"websocket"};
} UpgradeValues;
struct {
const std::string Text{"text/plain"};
const std::string TextEventStream{"text/event-stream"};
const std::string TextUtf8{"text/plain; charset=UTF-8"}; // TODO(jmarantz): fold this into Text
const std::string Html{"text/html; charset=UTF-8"};
const std::string Grpc{"application/grpc"};
const std::string GrpcWeb{"application/grpc-web"};
const std::string GrpcWebProto{"application/grpc-web+proto"};
const std::string GrpcWebText{"application/grpc-web-text"};
const std::string GrpcWebTextProto{"application/grpc-web-text+proto"};
const std::string Json{"application/json"};
const std::string Protobuf{"application/x-protobuf"};
const std::string FormUrlEncoded{"application/x-www-form-urlencoded"};
} ContentTypeValues;
struct {
const std::string True{"true"};
} EnvoyImmediateHealthCheckFailValues;
struct {
const std::string True{"true"};
} EnvoyInternalRequestValues;
struct {
const std::string True{"true"};
} EnvoyOverloadedValues;
struct {
const std::string True{"true"};
} EnvoyRateLimitedValues;
struct {
const std::string _5xx{"5xx"};
const std::string GatewayError{"gateway-error"};
const std::string ConnectFailure{"connect-failure"};
const std::string EnvoyRateLimited{"envoy-ratelimited"};
const std::string RefusedStream{"refused-stream"};
const std::string Retriable4xx{"retriable-4xx"};
const std::string RetriableStatusCodes{"retriable-status-codes"};
const std::string RetriableHeaders{"retriable-headers"};
const std::string Reset{"reset"};
} EnvoyRetryOnValues;
struct {
const std::string Cancelled{"cancelled"};
const std::string DeadlineExceeded{"deadline-exceeded"};
const std::string ResourceExhausted{"resource-exhausted"};
const std::string Unavailable{"unavailable"};
const std::string Internal{"internal"};
} EnvoyRetryOnGrpcValues;
struct {
const std::string _100Continue{"100-continue"};
} ExpectValues;
struct {
const std::string Connect{"CONNECT"};
const std::string Delete{"DELETE"};
const std::string Get{"GET"};
const std::string Head{"HEAD"};
const std::string Options{"OPTIONS"};
const std::string Patch{"PATCH"};
const std::string Post{"POST"};
const std::string Put{"PUT"};
const std::string Trace{"TRACE"};
} MethodValues;
struct {
// per https://tools.ietf.org/html/draft-kinnear-httpbis-http2-transport-02
const std::string Bytestream{"bytestream"};
} ProtocolValues;
struct {
const std::string Http{"http"};
const std::string Https{"https"};
} SchemeValues;
struct {
const std::string Brotli{"br"};
const std::string Compress{"compress"};
const std::string Chunked{"chunked"};
const std::string Deflate{"deflate"};
const std::string Gzip{"gzip"};
const std::string Identity{"identity"};
} TransferEncodingValues;
struct {
const std::string EnvoyHealthChecker{"Envoy/HC"};
} UserAgentValues;
struct {
const std::string Trailers{"trailers"};
} TEValues;
struct {
const std::string Nosniff{"nosniff"};
} XContentTypeOptionValues;
struct {
const std::string Http10String{"HTTP/1.0"};
const std::string Http11String{"HTTP/1.1"};
const std::string Http2String{"HTTP/2"};
const std::string Http3String{"HTTP/3"};
} ProtocolStrings;
};
using Headers = ConstSingleton<HeaderValues>;
} // namespace Http
} // namespace Envoy