forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http2_integration_test.cc
548 lines (453 loc) · 22.8 KB
/
http2_integration_test.cc
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
#include "test/integration/http2_integration_test.h"
#include <string>
#include "common/buffer/buffer_impl.h"
#include "common/http/header_map_impl.h"
#include "test/integration/utility.h"
#include "test/mocks/http/mocks.h"
#include "test/test_common/network_utility.h"
#include "test/test_common/printers.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
using ::testing::MatchesRegex;
namespace Envoy {
INSTANTIATE_TEST_CASE_P(IpVersions, Http2IntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(Http2IntegrationTest, RouterNotFound) { testRouterNotFound(); }
TEST_P(Http2IntegrationTest, RouterNotFoundBodyNoBuffer) { testRouterNotFoundWithBody(); }
TEST_P(Http2IntegrationTest, RouterClusterNotFound404) { testRouterClusterNotFound404(); }
TEST_P(Http2IntegrationTest, RouterClusterNotFound503) { testRouterClusterNotFound503(); }
TEST_P(Http2IntegrationTest, RouterRedirect) { testRouterRedirect(); }
TEST_P(Http2IntegrationTest, ValidZeroLengthContent) { testValidZeroLengthContent(); }
TEST_P(Http2IntegrationTest, InvalidContentLength) { testInvalidContentLength(); }
TEST_P(Http2IntegrationTest, MultipleContentLengths) { testMultipleContentLengths(); }
TEST_P(Http2IntegrationTest, ComputedHealthCheck) { testComputedHealthCheck(); }
TEST_P(Http2IntegrationTest, DrainClose) { testDrainClose(); }
TEST_P(Http2IntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false);
}
TEST_P(Http2IntegrationTest, FlowControlOnAndGiantBody) {
config_helper_.setBufferLimits(1024, 1024); // Set buffer limits upstream and downstream.
testRouterRequestAndResponseWithBody(1024 * 1024, 1024 * 1024, false);
}
TEST_P(Http2IntegrationTest, RouterHeaderOnlyRequestAndResponseNoBuffer) {
testRouterHeaderOnlyRequestAndResponse(true);
}
TEST_P(Http2IntegrationTest, RouterRequestAndResponseLargeHeaderNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, true);
}
TEST_P(Http2IntegrationTest, ShutdownWithActiveConnPoolConnections) {
testRouterHeaderOnlyRequestAndResponse(false);
}
TEST_P(Http2IntegrationTest, RouterUpstreamDisconnectBeforeRequestcomplete) {
testRouterUpstreamDisconnectBeforeRequestComplete();
}
TEST_P(Http2IntegrationTest, RouterUpstreamDisconnectBeforeResponseComplete) {
testRouterUpstreamDisconnectBeforeResponseComplete();
}
TEST_P(Http2IntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
testRouterDownstreamDisconnectBeforeRequestComplete();
}
TEST_P(Http2IntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
testRouterDownstreamDisconnectBeforeResponseComplete();
}
TEST_P(Http2IntegrationTest, RouterUpstreamResponseBeforeRequestComplete) {
testRouterUpstreamResponseBeforeRequestComplete();
}
TEST_P(Http2IntegrationTest, TwoRequests) { testTwoRequests(); }
TEST_P(Http2IntegrationTest, Retry) { testRetry(); }
TEST_P(Http2IntegrationTest, EnvoyHandling100Continue) { testEnvoyHandling100Continue(); }
TEST_P(Http2IntegrationTest, EnvoyHandlingDuplicate100Continue) {
testEnvoyHandling100Continue(true);
}
TEST_P(Http2IntegrationTest, EnvoyProxyingEarly100Continue) { testEnvoyProxying100Continue(true); }
TEST_P(Http2IntegrationTest, EnvoyProxyingLate100Continue) { testEnvoyProxying100Continue(false); }
TEST_P(Http2IntegrationTest, RetryHittingBufferLimit) { testRetryHittingBufferLimit(); }
TEST_P(Http2IntegrationTest, HittingDecoderFilterLimit) { testHittingDecoderFilterLimit(); }
TEST_P(Http2IntegrationTest, HittingEncoderFilterLimit) { testHittingEncoderFilterLimit(); }
TEST_P(Http2IntegrationTest, GrpcRetry) { testGrpcRetry(); }
// Send a request with overly large headers, and ensure it results in stream reset.
TEST_P(Http2IntegrationTest, MaxHeadersInCodec) {
Http::TestHeaderMapImpl big_headers{
{":method", "GET"}, {":path", "/test/long/url"}, {":scheme", "http"}, {":authority", "host"}};
big_headers.addCopy("big", std::string(63 * 1024, 'a'));
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
codec_client_->startRequest(big_headers, *response_);
response_->waitForReset();
codec_client_->close();
}
TEST_P(Http2IntegrationTest, DownstreamResetBeforeResponseComplete) {
testDownstreamResetBeforeResponseComplete();
}
TEST_P(Http2IntegrationTest, BadMagic) {
initialize();
Buffer::OwnedImpl buffer("hello");
std::string response;
RawConnectionDriver connection(
lookupPort("http"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(TestUtility::bufferToString(data));
},
version_);
connection.run();
EXPECT_EQ("", response);
}
TEST_P(Http2IntegrationTest, BadFrame) {
initialize();
Buffer::OwnedImpl buffer("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\nhelloworldcauseanerror");
std::string response;
RawConnectionDriver connection(
lookupPort("http"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(TestUtility::bufferToString(data));
},
version_);
connection.run();
EXPECT_TRUE(response.find("SETTINGS expected") != std::string::npos);
}
// Send client headers, a GoAway and then a body and ensure the full request and
// response are received.
TEST_P(Http2IntegrationTest, GoAway) {
config_helper_.addFilter(ConfigHelper::DEFAULT_HEALTH_CHECK_FILTER);
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
request_encoder_ = &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "GET"},
{":path", "/healthcheck"},
{":scheme", "http"},
{":authority", "host"}},
*response_);
codec_client_->goAway();
codec_client_->sendData(*request_encoder_, 0, true);
response_->waitForEndStream();
codec_client_->close();
EXPECT_TRUE(response_->complete());
EXPECT_STREQ("200", response_->headers().Status()->value().c_str());
}
TEST_P(Http2IntegrationTest, Trailers) { testTrailers(1024, 2048); }
TEST_P(Http2IntegrationTest, TrailersGiantBody) { testTrailers(1024 * 1024, 1024 * 1024); }
// Tests idle timeout behaviour with single request and validates that idle timer kicks in
// after given timeout.
TEST_P(Http2IntegrationTest, IdleTimoutBasic) { testIdleTimeoutBasic(); }
// Tests idle timeout behaviour with multiple requests and validates that idle timer kicks in
// after both the requests are done.
TEST_P(Http2IntegrationTest, IdleTimeoutWithTwoRequests) { testIdleTimeoutWithTwoRequests(); }
// Interleave two requests and responses and make sure that idle timeout is handled correctly.
TEST_P(Http2IntegrationTest, IdleTimeoutWithSimultaneousRequests) {
FakeHttpConnectionPtr fake_upstream_connection1;
FakeHttpConnectionPtr fake_upstream_connection2;
Http::StreamEncoder* encoder1;
Http::StreamEncoder* encoder2;
IntegrationStreamDecoderPtr response1(new IntegrationStreamDecoder(*dispatcher_));
IntegrationStreamDecoderPtr response2(new IntegrationStreamDecoder(*dispatcher_));
FakeStreamPtr upstream_request1;
FakeStreamPtr upstream_request2;
int32_t request1_bytes = 1024;
int32_t request2_bytes = 512;
config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
auto* http_protocol_options = cluster->mutable_common_http_protocol_options();
auto* idle_time_out = http_protocol_options->mutable_idle_timeout();
std::chrono::milliseconds timeout(1000);
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(timeout);
idle_time_out->set_seconds(seconds.count());
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Start request 1
encoder1 = &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
*response1);
fake_upstream_connection1 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_);
upstream_request1 = fake_upstream_connection1->waitForNewStream(*dispatcher_);
// Start request 2
response2.reset(new IntegrationStreamDecoder(*dispatcher_));
encoder2 = &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
*response2);
fake_upstream_connection2 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_);
upstream_request2 = fake_upstream_connection2->waitForNewStream(*dispatcher_);
// Finish request 1
codec_client_->sendData(*encoder1, request1_bytes, true);
upstream_request1->waitForEndStream(*dispatcher_);
// Finish request 2
codec_client_->sendData(*encoder2, request2_bytes, true);
upstream_request2->waitForEndStream(*dispatcher_);
// Respond to request 2
upstream_request2->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false);
upstream_request2->encodeData(request2_bytes, true);
response2->waitForEndStream();
EXPECT_TRUE(upstream_request2->complete());
EXPECT_EQ(request2_bytes, upstream_request2->bodyLength());
EXPECT_TRUE(response2->complete());
EXPECT_STREQ("200", response2->headers().Status()->value().c_str());
EXPECT_EQ(request2_bytes, response2->body().size());
// Validate that idle time is not kicked in.
EXPECT_EQ(0, test_server_->counter("cluster.cluster_0.upstream_cx_idle_timeout")->value());
EXPECT_NE(0, test_server_->counter("cluster.cluster_0.upstream_cx_total")->value());
// Respond to request 1
upstream_request1->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false);
upstream_request1->encodeData(request1_bytes, true);
response1->waitForEndStream();
EXPECT_TRUE(upstream_request1->complete());
EXPECT_EQ(request1_bytes, upstream_request1->bodyLength());
EXPECT_TRUE(response1->complete());
EXPECT_STREQ("200", response1->headers().Status()->value().c_str());
EXPECT_EQ(request1_bytes, response1->body().size());
// Do not send any requests and validate idle timeout kicks in after both the requests are done.
fake_upstream_connection1->waitForDisconnect();
fake_upstream_connection2->waitForDisconnect();
test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_idle_timeout", 2);
}
// Interleave two requests and responses and make sure the HTTP2 stack handles this correctly.
void Http2IntegrationTest::simultaneousRequest(int32_t request1_bytes, int32_t request2_bytes) {
FakeHttpConnectionPtr fake_upstream_connection1;
FakeHttpConnectionPtr fake_upstream_connection2;
Http::StreamEncoder* encoder1;
Http::StreamEncoder* encoder2;
IntegrationStreamDecoderPtr response1(new IntegrationStreamDecoder(*dispatcher_));
IntegrationStreamDecoderPtr response2(new IntegrationStreamDecoder(*dispatcher_));
FakeStreamPtr upstream_request1;
FakeStreamPtr upstream_request2;
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Start request 1
encoder1 = &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
*response1);
fake_upstream_connection1 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_);
upstream_request1 = fake_upstream_connection1->waitForNewStream(*dispatcher_);
// Start request 2
response2.reset(new IntegrationStreamDecoder(*dispatcher_));
encoder2 = &codec_client_->startRequest(Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
*response2);
fake_upstream_connection2 = fake_upstreams_[0]->waitForHttpConnection(*dispatcher_);
upstream_request2 = fake_upstream_connection2->waitForNewStream(*dispatcher_);
// Finish request 1
codec_client_->sendData(*encoder1, request1_bytes, true);
upstream_request1->waitForEndStream(*dispatcher_);
// Finish request 2
codec_client_->sendData(*encoder2, request2_bytes, true);
upstream_request2->waitForEndStream(*dispatcher_);
// Respond to request 2
upstream_request2->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false);
upstream_request2->encodeData(request2_bytes, true);
response2->waitForEndStream();
EXPECT_TRUE(upstream_request2->complete());
EXPECT_EQ(request2_bytes, upstream_request2->bodyLength());
EXPECT_TRUE(response2->complete());
EXPECT_STREQ("200", response2->headers().Status()->value().c_str());
EXPECT_EQ(request2_bytes, response2->body().size());
// Respond to request 1
upstream_request1->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false);
upstream_request1->encodeData(request2_bytes, true);
response1->waitForEndStream();
EXPECT_TRUE(upstream_request1->complete());
EXPECT_EQ(request1_bytes, upstream_request1->bodyLength());
EXPECT_TRUE(response1->complete());
EXPECT_STREQ("200", response1->headers().Status()->value().c_str());
EXPECT_EQ(request2_bytes, response1->body().size());
// Cleanup both downstream and upstream
codec_client_->close();
fake_upstream_connection1->close();
fake_upstream_connection1->waitForDisconnect();
fake_upstream_connection2->close();
fake_upstream_connection2->waitForDisconnect();
}
TEST_P(Http2IntegrationTest, SimultaneousRequest) { simultaneousRequest(1024, 512); }
TEST_P(Http2IntegrationTest, SimultaneousRequestWithBufferLimits) {
config_helper_.setBufferLimits(1024, 1024); // Set buffer limits upstream and downstream.
simultaneousRequest(1024 * 32, 1024 * 16);
}
Http2RingHashIntegrationTest::Http2RingHashIntegrationTest() {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
auto* cluster = bootstrap.mutable_static_resources()->mutable_clusters(0);
cluster->clear_hosts();
cluster->set_lb_policy(envoy::api::v2::Cluster_LbPolicy_RING_HASH);
for (int i = 0; i < num_upstreams_; i++) {
auto* socket = cluster->add_hosts()->mutable_socket_address();
socket->set_address(Network::Test::getLoopbackAddressString(version_));
}
});
}
Http2RingHashIntegrationTest::~Http2RingHashIntegrationTest() {
if (codec_client_) {
codec_client_->close();
codec_client_ = nullptr;
}
for (auto it = fake_upstream_connections_.begin(); it != fake_upstream_connections_.end(); ++it) {
(*it)->close();
(*it)->waitForDisconnect();
}
}
void Http2RingHashIntegrationTest::createUpstreams() {
for (int i = 0; i < num_upstreams_; i++) {
fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_));
}
}
INSTANTIATE_TEST_CASE_P(IpVersions, Http2RingHashIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
void Http2RingHashIntegrationTest::sendMultipleRequests(
int request_bytes, Http::TestHeaderMapImpl headers,
std::function<void(IntegrationStreamDecoder&)> cb) {
TestRandomGenerator rand;
const uint32_t num_requests = 50;
std::vector<Http::StreamEncoder*> encoders;
std::vector<IntegrationStreamDecoderPtr> responses;
std::vector<FakeStreamPtr> upstream_requests;
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
for (uint32_t i = 0; i < num_requests; ++i) {
responses.push_back(IntegrationStreamDecoderPtr{new IntegrationStreamDecoder(*dispatcher_)});
encoders.push_back(&codec_client_->startRequest(headers, *responses[i]));
codec_client_->sendData(*encoders[i], request_bytes, true);
}
for (uint32_t i = 0; i < num_requests; ++i) {
auto fake_upstream_connection =
FakeUpstream::waitForHttpConnection(*dispatcher_, fake_upstreams_);
// As data and streams are interwoven, make sure waitForNewStream()
// ignores incoming data and waits for actual stream establishment.
upstream_requests.push_back(fake_upstream_connection->waitForNewStream(*dispatcher_, true));
upstream_requests.back()->setAddServedByHeader(true);
fake_upstream_connections_.push_back(std::move(fake_upstream_connection));
}
for (uint32_t i = 0; i < num_requests; ++i) {
upstream_requests[i]->waitForEndStream(*dispatcher_);
upstream_requests[i]->encodeHeaders(Http::TestHeaderMapImpl{{":status", "200"}}, false);
upstream_requests[i]->encodeData(rand.random() % (1024 * 2), true);
}
for (uint32_t i = 0; i < num_requests; ++i) {
responses[i]->waitForEndStream();
EXPECT_TRUE(upstream_requests[i]->complete());
EXPECT_EQ(request_bytes, upstream_requests[i]->bodyLength());
EXPECT_TRUE(responses[i]->complete());
cb(*responses[i]);
}
}
TEST_P(Http2RingHashIntegrationTest, CookieRoutingNoCookieNoTtl) {
config_helper_.addConfigModifier(
[&](envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager& hcm)
-> void {
auto* hash_policy = hcm.mutable_route_config()
->mutable_virtual_hosts(0)
->mutable_routes(0)
->mutable_route()
->add_hash_policy();
auto* cookie = hash_policy->mutable_cookie();
cookie->set_name("foo");
});
// This test is non-deterministic, so make it extremely unlikely that not all
// upstreams get hit.
num_upstreams_ = 2;
std::set<std::string> served_by;
sendMultipleRequests(
1024,
Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
[&](IntegrationStreamDecoder& response) {
EXPECT_STREQ("200", response.headers().Status()->value().c_str());
EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr);
served_by.insert(
response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str());
});
EXPECT_EQ(served_by.size(), num_upstreams_);
}
TEST_P(Http2RingHashIntegrationTest, CookieRoutingNoCookieWithTtlSet) {
config_helper_.addConfigModifier(
[&](envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager& hcm)
-> void {
auto* hash_policy = hcm.mutable_route_config()
->mutable_virtual_hosts(0)
->mutable_routes(0)
->mutable_route()
->add_hash_policy();
auto* cookie = hash_policy->mutable_cookie();
cookie->set_name("foo");
cookie->mutable_ttl()->set_seconds(15);
});
std::set<std::string> set_cookies;
sendMultipleRequests(
1024,
Http::TestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
[&](IntegrationStreamDecoder& response) {
EXPECT_STREQ("200", response.headers().Status()->value().c_str());
std::string value = response.headers().get(Http::Headers::get().SetCookie)->value().c_str();
set_cookies.insert(value);
EXPECT_THAT(value, MatchesRegex("foo=.*; Max-Age=15"));
});
EXPECT_EQ(set_cookies.size(), 1);
}
TEST_P(Http2RingHashIntegrationTest, CookieRoutingWithCookieNoTtl) {
config_helper_.addConfigModifier(
[&](envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager& hcm)
-> void {
auto* hash_policy = hcm.mutable_route_config()
->mutable_virtual_hosts(0)
->mutable_routes(0)
->mutable_route()
->add_hash_policy();
auto* cookie = hash_policy->mutable_cookie();
cookie->set_name("foo");
});
std::set<std::string> served_by;
sendMultipleRequests(
1024,
Http::TestHeaderMapImpl{{":method", "POST"},
{"cookie", "foo=bar"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
[&](IntegrationStreamDecoder& response) {
EXPECT_STREQ("200", response.headers().Status()->value().c_str());
EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr);
served_by.insert(
response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str());
});
EXPECT_EQ(served_by.size(), 1);
}
TEST_P(Http2RingHashIntegrationTest, CookieRoutingWithCookieWithTtlSet) {
config_helper_.addConfigModifier(
[&](envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager& hcm)
-> void {
auto* hash_policy = hcm.mutable_route_config()
->mutable_virtual_hosts(0)
->mutable_routes(0)
->mutable_route()
->add_hash_policy();
auto* cookie = hash_policy->mutable_cookie();
cookie->set_name("foo");
cookie->mutable_ttl()->set_seconds(15);
});
std::set<std::string> served_by;
sendMultipleRequests(
1024,
Http::TestHeaderMapImpl{{":method", "POST"},
{"cookie", "foo=bar"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
[&](IntegrationStreamDecoder& response) {
EXPECT_STREQ("200", response.headers().Status()->value().c_str());
EXPECT_TRUE(response.headers().get(Http::Headers::get().SetCookie) == nullptr);
served_by.insert(
response.headers().get(Http::LowerCaseString("x-served-by"))->value().c_str());
});
EXPECT_EQ(served_by.size(), 1);
}
} // namespace Envoy