forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.cc
1374 lines (1165 loc) · 60.6 KB
/
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "test/integration/integration_test.h"
#include <string>
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/route/v3/route_components.pb.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "common/http/header_map_impl.h"
#include "common/http/headers.h"
#include "common/network/socket_option_impl.h"
#include "common/network/utility.h"
#include "common/protobuf/utility.h"
#include "test/integration/autonomous_upstream.h"
#include "test/integration/filters/process_context_filter.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 Envoy::Http::Headers;
using Envoy::Http::HeaderValueOf;
using Envoy::Http::HttpStatusIs;
using testing::EndsWith;
using testing::HasSubstr;
using testing::Not;
namespace Envoy {
namespace {
std::string normalizeDate(const std::string& s) {
const std::regex date_regex("date:[^\r]+");
return std::regex_replace(s, date_regex, "date: Mon, 01 Jan 2017 00:00:00 GMT");
}
void setDisallowAbsoluteUrl(
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& hcm) {
hcm.mutable_http_protocol_options()->mutable_allow_absolute_url()->set_value(false);
};
void setAllowHttp10WithDefaultHost(
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& hcm) {
hcm.mutable_http_protocol_options()->set_accept_http_10(true);
hcm.mutable_http_protocol_options()->set_default_host_for_http_10("default.com");
}
} // namespace
INSTANTIATE_TEST_SUITE_P(IpVersions, IntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
// Make sure we have correctly specified per-worker performance stats.
TEST_P(IntegrationTest, PerWorkerStatsAndBalancing) {
concurrency_ = 2;
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
listener->mutable_connection_balance_config()->mutable_exact_balance();
});
initialize();
// Per-worker listener stats.
auto check_listener_stats = [this](uint64_t cx_active, uint64_t cx_total) {
if (GetParam() == Network::Address::IpVersion::v4) {
test_server_->waitForGaugeEq("listener.127.0.0.1_0.worker_0.downstream_cx_active", cx_active);
test_server_->waitForGaugeEq("listener.127.0.0.1_0.worker_1.downstream_cx_active", cx_active);
test_server_->waitForCounterEq("listener.127.0.0.1_0.worker_0.downstream_cx_total", cx_total);
test_server_->waitForCounterEq("listener.127.0.0.1_0.worker_1.downstream_cx_total", cx_total);
} else {
test_server_->waitForGaugeEq("listener.[__1]_0.worker_0.downstream_cx_active", cx_active);
test_server_->waitForGaugeEq("listener.[__1]_0.worker_1.downstream_cx_active", cx_active);
test_server_->waitForCounterEq("listener.[__1]_0.worker_0.downstream_cx_total", cx_total);
test_server_->waitForCounterEq("listener.[__1]_0.worker_1.downstream_cx_total", cx_total);
}
};
check_listener_stats(0, 0);
// Main thread admin listener stats.
EXPECT_NE(nullptr, test_server_->counter("listener.admin.main_thread.downstream_cx_total"));
// Per-thread watchdog stats.
EXPECT_NE(nullptr, test_server_->counter("server.main_thread.watchdog_miss"));
EXPECT_NE(nullptr, test_server_->counter("server.worker_0.watchdog_miss"));
EXPECT_NE(nullptr, test_server_->counter("server.worker_1.watchdog_miss"));
codec_client_ = makeHttpConnection(lookupPort("http"));
IntegrationCodecClientPtr codec_client2 = makeHttpConnection(lookupPort("http"));
check_listener_stats(1, 1);
codec_client_->close();
codec_client2->close();
check_listener_stats(0, 1);
}
// Validates that the drain actually drains the listeners.
TEST_P(IntegrationTest, AdminDrainDrainsListeners) { testAdminDrain(downstreamProtocol()); }
TEST_P(IntegrationTest, RouterDirectResponse) {
const std::string body = "Response body";
const std::string file_path = TestEnvironment::writeStringToFileForTest("test_envoy", body);
static const std::string domain("direct.example.com");
static const std::string prefix("/");
static const Http::Code status(Http::Code::OK);
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
auto* route_config = hcm.mutable_route_config();
auto* header_value_option = route_config->mutable_response_headers_to_add()->Add();
header_value_option->mutable_header()->set_key("x-additional-header");
header_value_option->mutable_header()->set_value("example-value");
header_value_option->mutable_append()->set_value(false);
header_value_option = route_config->mutable_response_headers_to_add()->Add();
header_value_option->mutable_header()->set_key("content-type");
header_value_option->mutable_header()->set_value("text/html");
header_value_option->mutable_append()->set_value(false);
auto* virtual_host = route_config->add_virtual_hosts();
virtual_host->set_name(domain);
virtual_host->add_domains(domain);
virtual_host->add_routes()->mutable_match()->set_prefix(prefix);
virtual_host->mutable_routes(0)->mutable_direct_response()->set_status(
static_cast<uint32_t>(status));
virtual_host->mutable_routes(0)->mutable_direct_response()->mutable_body()->set_filename(
file_path);
});
initialize();
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("http"), "GET", "/", "", downstream_protocol_, version_, "direct.example.com");
ASSERT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
EXPECT_EQ("example-value", response->headers()
.get(Envoy::Http::LowerCaseString("x-additional-header"))
->value()
.getStringView());
EXPECT_EQ("text/html", response->headers().ContentType()->value().getStringView());
EXPECT_EQ(body, response->body());
}
TEST_P(IntegrationTest, ConnectionClose) {
config_helper_.addFilter(ConfigHelper::defaultHealthCheckFilter());
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
codec_client_->makeHeaderOnlyRequest(Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/healthcheck"},
{":authority", "host"},
{"connection", "close"}});
response->waitForEndStream();
codec_client_->waitForDisconnect();
EXPECT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
}
TEST_P(IntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false, false);
}
TEST_P(IntegrationTest, RouterRequestAndResponseWithGiantBodyNoBuffer) {
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, false);
}
TEST_P(IntegrationTest, FlowControlOnAndGiantBody) {
config_helper_.setBufferLimits(1024, 1024);
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, false);
}
TEST_P(IntegrationTest, LargeFlowControlOnAndGiantBody) {
config_helper_.setBufferLimits(128 * 1024, 128 * 1024);
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, false);
}
TEST_P(IntegrationTest, RouterRequestAndResponseWithBodyAndContentLengthNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false, true);
}
TEST_P(IntegrationTest, RouterRequestAndResponseWithGiantBodyAndContentLengthNoBuffer) {
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, true);
}
TEST_P(IntegrationTest, FlowControlOnAndGiantBodyWithContentLength) {
config_helper_.setBufferLimits(1024, 1024);
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, true);
}
TEST_P(IntegrationTest, LargeFlowControlOnAndGiantBodyWithContentLength) {
config_helper_.setBufferLimits(128 * 1024, 128 * 1024);
testRouterRequestAndResponseWithBody(10 * 1024 * 1024, 10 * 1024 * 1024, false, true);
}
TEST_P(IntegrationTest, RouterRequestAndResponseLargeHeaderNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, true);
}
TEST_P(IntegrationTest, RouterHeaderOnlyRequestAndResponseNoBuffer) {
testRouterHeaderOnlyRequestAndResponse();
}
TEST_P(IntegrationTest, RouterUpstreamDisconnectBeforeRequestcomplete) {
testRouterUpstreamDisconnectBeforeRequestComplete();
}
TEST_P(IntegrationTest, RouterUpstreamDisconnectBeforeResponseComplete) {
testRouterUpstreamDisconnectBeforeResponseComplete();
}
// Regression test for https://github.com/envoyproxy/envoy/issues/9508
TEST_P(IntegrationTest, ResponseFramedByConnectionCloseWithReadLimits) {
// Set a small buffer limit on the downstream in order to trigger a call to trigger readDisable on
// the upstream when proxying the response. Upstream limit needs to be larger so that
// RawBufferSocket::doRead reads the response body and detects the upstream close in the same call
// stack.
config_helper_.setBufferLimits(100000, 1);
initialize();
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
// Disable chunk encoding to trigger framing by connection close.
upstream_request_->http1StreamEncoderOptions().value().get().disableChunkEncoding();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, false);
upstream_request_->encodeData(512, true);
ASSERT_TRUE(fake_upstream_connection_->close());
response->waitForEndStream();
EXPECT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
EXPECT_EQ(512, response->body().size());
}
TEST_P(IntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
testRouterDownstreamDisconnectBeforeRequestComplete();
}
TEST_P(IntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
testRouterDownstreamDisconnectBeforeResponseComplete();
}
TEST_P(IntegrationTest, RouterUpstreamResponseBeforeRequestComplete) {
testRouterUpstreamResponseBeforeRequestComplete();
}
TEST_P(IntegrationTest, EnvoyProxyingEarly100ContinueWithEncoderFilter) {
testEnvoyProxying100Continue(true, true);
}
TEST_P(IntegrationTest, EnvoyProxyingLate100ContinueWithEncoderFilter) {
testEnvoyProxying100Continue(false, true);
}
// Regression test for https://github.com/envoyproxy/envoy/issues/10923.
TEST_P(IntegrationTest, EnvoyProxying100ContinueWithDecodeDataPause) {
config_helper_.addFilter(R"EOF(
name: stop-iteration-and-continue-filter
typed_config:
"@type": type.googleapis.com/google.protobuf.Empty
)EOF");
testEnvoyProxying100Continue(true);
}
// This is a regression for https://github.com/envoyproxy/envoy/issues/2715 and validates that a
// pending request is not sent on a connection that has been half-closed.
TEST_P(IntegrationTest, UpstreamDisconnectWithTwoRequests) {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
// Ensure we only have one connection upstream, one request active at a time.
cluster->mutable_max_requests_per_connection()->set_value(1);
auto* circuit_breakers = cluster->mutable_circuit_breakers();
circuit_breakers->add_thresholds()->mutable_max_connections()->set_value(1);
});
initialize();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
codec_client_ = makeHttpConnection(lookupPort("http"));
// Request 1.
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 1024);
waitForNextUpstreamRequest();
// Request 2.
IntegrationCodecClientPtr codec_client2 = makeHttpConnection(lookupPort("http"));
auto response2 = codec_client2->makeRequestWithBody(default_request_headers_, 512);
// Validate one request active, the other pending.
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_active", 1);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_pending_active", 1);
// Response 1.
upstream_request_->encodeHeaders(default_response_headers_, false);
upstream_request_->encodeData(512, true);
ASSERT_TRUE(fake_upstream_connection_->close());
response->waitForEndStream();
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_total", 1);
test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_200", 1);
// Response 2.
ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect());
fake_upstream_connection_.reset();
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(default_response_headers_, false);
upstream_request_->encodeData(1024, true);
response2->waitForEndStream();
codec_client2->close();
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(response2->complete());
EXPECT_EQ("200", response2->headers().Status()->value().getStringView());
test_server_->waitForCounterGe("cluster.cluster_0.upstream_cx_total", 2);
test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_200", 2);
}
// Test hitting the bridge filter with too many response bytes to buffer. Given
// the headers are not proxied, the connection manager will send a local error reply.
TEST_P(IntegrationTest, HittingGrpcFilterLimitBufferingHeaders) {
config_helper_.addFilter(
"{ name: grpc_http1_bridge, typed_config: { \"@type\": "
"type.googleapis.com/envoy.config.filter.http.grpc_http1_bridge.v2.Config } }");
config_helper_.setBufferLimits(1024, 1024);
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"},
{"content-type", "application/grpc"},
{"x-envoy-retry-grpc-on", "cancelled"}});
waitForNextUpstreamRequest();
// Send the overly large response. Because the grpc_http1_bridge filter buffers and buffer
// limits are exceeded, this will be translated into an unknown gRPC error.
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, false);
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
upstream_request_->encodeData(1024 * 65, false);
ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect());
response->waitForEndStream();
EXPECT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
EXPECT_THAT(response->headers(),
HeaderValueOf(Headers::get().GrpcStatus, "2")); // Unknown gRPC error
}
TEST_P(IntegrationTest, TestSmuggling) {
initialize();
const std::string smuggled_request = "GET / HTTP/1.1\r\nHost: disallowed\r\n\r\n";
ASSERT_EQ(smuggled_request.length(), 36);
// Make sure the http parser rejects having content-length and transfer-encoding: chunked
// on the same request, regardless of order and spacing.
{
std::string response;
const std::string full_request =
"GET / HTTP/1.1\r\nHost: host\r\ncontent-length: 36\r\ntransfer-encoding: chunked\r\n\r\n" +
smuggled_request;
sendRawHttpAndWaitForResponse(lookupPort("http"), full_request.c_str(), &response, false);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n",
response);
}
{
std::string response;
const std::string request = "GET / HTTP/1.1\r\nHost: host\r\ntransfer-encoding: chunked "
"\r\ncontent-length: 36\r\n\r\n" +
smuggled_request;
sendRawHttpAndWaitForResponse(lookupPort("http"), request.c_str(), &response, false);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n",
response);
}
{
std::string response;
const std::string request = "GET / HTTP/1.1\r\nHost: host\r\ntransfer-encoding: "
"identity,chunked \r\ncontent-length: 36\r\n\r\n" +
smuggled_request;
sendRawHttpAndWaitForResponse(lookupPort("http"), request.c_str(), &response, false);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n",
response);
}
}
TEST_P(IntegrationTest, BadFirstline) {
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "hello", &response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
}
TEST_P(IntegrationTest, MissingDelimiter) {
useAccessLog("%RESPONSE_CODE_DETAILS%");
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET / HTTP/1.1\r\nHost: host\r\nfoo bar\r\n\r\n", &response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("http1.codec_error"));
}
TEST_P(IntegrationTest, InvalidCharacterInFirstline) {
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GE(T / HTTP/1.1\r\nHost: host\r\n\r\n",
&response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
}
TEST_P(IntegrationTest, InvalidVersion) {
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.01\r\nHost: host\r\n\r\n",
&response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
}
// Expect that malformed trailers to break the connection
TEST_P(IntegrationTest, BadTrailer) {
initialize();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"POST / HTTP/1.1\r\n"
"Host: host\r\n"
"Transfer-Encoding: chunked\r\n\r\n"
"4\r\n"
"body\r\n0\r\n"
"badtrailer\r\n\r\n",
&response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
}
// Expect malformed headers to break the connection
TEST_P(IntegrationTest, BadHeader) {
initialize();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"POST / HTTP/1.1\r\n"
"Host: host\r\n"
"badHeader\r\n"
"Transfer-Encoding: chunked\r\n\r\n"
"4\r\n"
"body\r\n0\r\n\r\n",
&response);
EXPECT_EQ("HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\nconnection: close\r\n\r\n", response);
}
TEST_P(IntegrationTest, Http10Disabled) {
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.0\r\n\r\n", &response, true);
EXPECT_TRUE(response.find("HTTP/1.1 426 Upgrade Required\r\n") == 0);
}
TEST_P(IntegrationTest, Http10DisabledWithUpgrade) {
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.0\r\nUpgrade: h2c\r\n\r\n",
&response, true);
EXPECT_TRUE(response.find("HTTP/1.1 426 Upgrade Required\r\n") == 0);
}
// Turn HTTP/1.0 support on and verify 09 style requests work.
TEST_P(IntegrationTest, Http09Enabled) {
useAccessLog();
autonomous_upstream_ = true;
config_helper_.addConfigModifier(&setAllowHttp10WithDefaultHost);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET /\r\n\r\n", &response, false);
EXPECT_THAT(response, HasSubstr("HTTP/1.0 200 OK\r\n"));
EXPECT_THAT(response, HasSubstr("connection: close"));
EXPECT_THAT(response, Not(HasSubstr("transfer-encoding: chunked\r\n")));
std::unique_ptr<Http::TestRequestHeaderMapImpl> upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_.front().get())->lastRequestHeaders();
ASSERT_TRUE(upstream_headers != nullptr);
EXPECT_EQ(upstream_headers->Host()->value(), "default.com");
EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("HTTP/1.0"));
}
// Turn HTTP/1.0 support on and verify the request is proxied and the default host is sent upstream.
TEST_P(IntegrationTest, Http10Enabled) {
autonomous_upstream_ = true;
config_helper_.addConfigModifier(&setAllowHttp10WithDefaultHost);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.0\r\n\r\n", &response, false);
EXPECT_THAT(response, HasSubstr("HTTP/1.0 200 OK\r\n"));
EXPECT_THAT(response, HasSubstr("connection: close"));
EXPECT_THAT(response, Not(HasSubstr("transfer-encoding: chunked\r\n")));
std::unique_ptr<Http::TestRequestHeaderMapImpl> upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_.front().get())->lastRequestHeaders();
ASSERT_TRUE(upstream_headers != nullptr);
EXPECT_EQ(upstream_headers->Host()->value(), "default.com");
sendRawHttpAndWaitForResponse(lookupPort("http"), "HEAD / HTTP/1.0\r\n\r\n", &response, false);
EXPECT_THAT(response, HasSubstr("HTTP/1.0 200 OK\r\n"));
EXPECT_THAT(response, HasSubstr("connection: close"));
EXPECT_THAT(response, Not(HasSubstr("transfer-encoding: chunked\r\n")));
}
TEST_P(IntegrationTest, TestInlineHeaders) {
autonomous_upstream_ = true;
config_helper_.addConfigModifier(&setAllowHttp10WithDefaultHost);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET / HTTP/1.1\r\n"
"Host: foo.com\r\n"
"Foo: bar\r\n"
"Cache-control: public\r\n"
"Cache-control: 123\r\n"
"Eep: baz\r\n\r\n",
&response, true);
EXPECT_THAT(response, HasSubstr("HTTP/1.1 200 OK\r\n"));
std::unique_ptr<Http::TestRequestHeaderMapImpl> upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_.front().get())->lastRequestHeaders();
ASSERT_TRUE(upstream_headers != nullptr);
EXPECT_EQ(upstream_headers->Host()->value(), "foo.com");
EXPECT_EQ(upstream_headers->CacheControl()->value(), "public,123");
ASSERT_TRUE(upstream_headers->get(Envoy::Http::LowerCaseString("foo")) != nullptr);
EXPECT_EQ("bar",
upstream_headers->get(Envoy::Http::LowerCaseString("foo"))->value().getStringView());
ASSERT_TRUE(upstream_headers->get(Envoy::Http::LowerCaseString("eep")) != nullptr);
EXPECT_EQ("baz",
upstream_headers->get(Envoy::Http::LowerCaseString("eep"))->value().getStringView());
}
// Verify for HTTP/1.0 a keep-alive header results in no connection: close.
// Also verify existing host headers are passed through for the HTTP/1.0 case.
// This also regression tests proper handling of trailing whitespace after key
// values, specifically the host header.
TEST_P(IntegrationTest, Http10WithHostandKeepAliveAndLwsNoContentLength) {
autonomous_upstream_ = true;
config_helper_.addConfigModifier(&setAllowHttp10WithDefaultHost);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET / HTTP/1.0\r\nHost: foo.com \r\nConnection:Keep-alive\r\n\r\n",
&response, true);
EXPECT_THAT(response, HasSubstr("HTTP/1.0 200 OK\r\n"));
EXPECT_THAT(response, HasSubstr("connection: close"));
EXPECT_THAT(response, Not(HasSubstr("connection: keep-alive")));
EXPECT_THAT(response, Not(HasSubstr("content-length:")));
EXPECT_THAT(response, Not(HasSubstr("transfer-encoding: chunked\r\n")));
std::unique_ptr<Http::TestRequestHeaderMapImpl> upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_.front().get())->lastRequestHeaders();
ASSERT_TRUE(upstream_headers != nullptr);
EXPECT_EQ(upstream_headers->Host()->value(), "foo.com");
}
TEST_P(IntegrationTest, Http10WithHostandKeepAliveAndContentLengthAndLws) {
autonomous_upstream_ = true;
config_helper_.addConfigModifier(&setAllowHttp10WithDefaultHost);
initialize();
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_.front().get())
->setResponseHeaders(std::make_unique<Http::TestResponseHeaderMapImpl>(
Http::TestHeaderMapImpl({{":status", "200"}, {"content-length", "10"}})));
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET / HTTP/1.0\r\nHost: foo.com \r\nConnection:Keep-alive\r\n\r\n",
&response, true);
EXPECT_THAT(response, HasSubstr("HTTP/1.0 200 OK\r\n"));
EXPECT_THAT(response, Not(HasSubstr("connection: close")));
EXPECT_THAT(response, HasSubstr("connection: keep-alive"));
EXPECT_THAT(response, HasSubstr("content-length:"));
EXPECT_THAT(response, Not(HasSubstr("transfer-encoding: chunked\r\n")));
}
TEST_P(IntegrationTest, Pipeline) {
autonomous_upstream_ = true;
initialize();
std::string response;
Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\nHost: host\r\n\r\nGET / HTTP/1.1\r\n\r\n");
RawConnectionDriver connection(
lookupPort("http"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(data.toString());
},
version_);
// First response should be success.
while (response.find("200") == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 200 OK\r\n"));
// Second response should be 400 (no host)
while (response.find("400") == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 400 Bad Request\r\n"));
connection.close();
}
// Checks to ensure that we reject the third request that is pipelined in the
// same request
TEST_P(IntegrationTest, PipelineWithTrailers) {
config_helper_.addConfigModifier(setEnableDownstreamTrailersHttp1());
config_helper_.addConfigModifier(setEnableUpstreamTrailersHttp1());
autonomous_upstream_ = true;
autonomous_allow_incomplete_streams_ = true;
initialize();
std::string response;
std::string good_request("POST / HTTP/1.1\r\n"
"Host: host\r\n"
"Transfer-Encoding: chunked\r\n\r\n"
"4\r\n"
"body\r\n0\r\n"
"trailer1:t2\r\n"
"trailer2:t3\r\n"
"\r\n");
std::string bad_request("POST / HTTP/1.1\r\n"
"Host: host\r\n"
"Transfer-Encoding: chunked\r\n\r\n"
"4\r\n"
"body\r\n0\r\n"
"trailer1\r\n"
"trailer2:t3\r\n"
"\r\n");
Buffer::OwnedImpl buffer(absl::StrCat(good_request, good_request, bad_request));
RawConnectionDriver connection(
lookupPort("http"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(data.toString());
},
version_);
// First response should be success.
size_t pos;
while ((pos = response.find("200")) == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 200 OK\r\n"));
while (response.find("200", pos + 1) == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
while (response.find("400") == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 400 Bad Request\r\n"));
connection.close();
}
// Add a pipeline test where complete request headers in the first request merit
// an inline sendLocalReply to make sure the "kick" works under the call stack
// of dispatch as well as when a response is proxied from upstream.
TEST_P(IntegrationTest, PipelineInline) {
autonomous_upstream_ = true;
initialize();
std::string response;
Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\n\r\nGET / HTTP/1.0\r\n\r\n");
RawConnectionDriver connection(
lookupPort("http"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(data.toString());
},
version_);
while (response.find("400") == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 400 Bad Request\r\n"));
while (response.find("426") == std::string::npos) {
connection.run(Event::Dispatcher::RunType::NonBlock);
}
EXPECT_THAT(response, HasSubstr("HTTP/1.1 426 Upgrade Required\r\n"));
connection.close();
}
TEST_P(IntegrationTest, NoHost) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
Http::TestRequestHeaderMapImpl request_headers{
{":method", "GET"}, {":path", "/test/long/url"}, {":scheme", "http"}};
auto response = codec_client_->makeHeaderOnlyRequest(request_headers);
response->waitForEndStream();
ASSERT_TRUE(response->complete());
EXPECT_EQ("400", response->headers().Status()->value().getStringView());
}
TEST_P(IntegrationTest, BadPath) {
config_helper_.addConfigModifier(&setDisallowAbsoluteUrl);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET http://api.lyft.com HTTP/1.1\r\nHost: host\r\n\r\n", &response,
true);
EXPECT_TRUE(response.find("HTTP/1.1 404 Not Found\r\n") == 0);
}
TEST_P(IntegrationTest, AbsolutePath) {
// Configure www.redirect.com to send a redirect, and ensure the redirect is
// encountered via absolute URL.
auto host = config_helper_.createVirtualHost("www.redirect.com", "/");
host.set_require_tls(envoy::config::route::v3::VirtualHost::ALL);
config_helper_.addVirtualHost(host);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET http://www.redirect.com HTTP/1.1\r\nHost: host\r\n\r\n",
&response, true);
EXPECT_FALSE(response.find("HTTP/1.1 404 Not Found\r\n") == 0);
}
TEST_P(IntegrationTest, AbsolutePathWithPort) {
// Configure www.namewithport.com:1234 to send a redirect, and ensure the redirect is
// encountered via absolute URL with a port.
auto host = config_helper_.createVirtualHost("www.namewithport.com:1234", "/");
host.set_require_tls(envoy::config::route::v3::VirtualHost::ALL);
config_helper_.addVirtualHost(host);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(
lookupPort("http"), "GET http://www.namewithport.com:1234 HTTP/1.1\r\nHost: host\r\n\r\n",
&response, true);
EXPECT_FALSE(response.find("HTTP/1.1 404 Not Found\r\n") == 0);
}
TEST_P(IntegrationTest, AbsolutePathWithoutPort) {
// Add a restrictive default match, to avoid the request hitting the * / catchall.
config_helper_.setDefaultHostAndRoute("foo.com", "/found");
// Set a matcher for www.namewithport.com:1234 and verify http://www.namewithport.com does not
// match
auto host = config_helper_.createVirtualHost("www.namewithport.com:1234", "/");
host.set_require_tls(envoy::config::route::v3::VirtualHost::ALL);
config_helper_.addVirtualHost(host);
initialize();
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"),
"GET http://www.namewithport.com HTTP/1.1\r\nHost: host\r\n\r\n",
&response, true);
EXPECT_TRUE(response.find("HTTP/1.1 404 Not Found\r\n") == 0) << response;
}
// Ensure that connect behaves the same with allow_absolute_url enabled and without
TEST_P(IntegrationTest, Connect) {
const std::string& request = "CONNECT www.somewhere.com:80 HTTP/1.1\r\nHost: host\r\n\r\n";
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
// Clone the whole listener.
auto static_resources = bootstrap.mutable_static_resources();
auto* old_listener = static_resources->mutable_listeners(0);
auto* cloned_listener = static_resources->add_listeners();
cloned_listener->CopyFrom(*old_listener);
old_listener->set_name("http_forward");
});
// Set the first listener to disallow absolute URLs.
config_helper_.addConfigModifier(&setDisallowAbsoluteUrl);
initialize();
std::string response1;
sendRawHttpAndWaitForResponse(lookupPort("http"), request.c_str(), &response1, true);
std::string response2;
sendRawHttpAndWaitForResponse(lookupPort("http_forward"), request.c_str(), &response2, true);
EXPECT_EQ(normalizeDate(response1), normalizeDate(response2));
}
TEST_P(IntegrationTest, UpstreamProtocolError) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder = codec_client_->startRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":path", "/test/long/url"}, {":authority", "host"}});
auto response = std::move(encoder_decoder.second);
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
// TODO(mattklein123): Waiting for exact amount of data is a hack. This needs to
// be fixed.
std::string data;
ASSERT_TRUE(fake_upstream_connection->waitForData(187, &data));
ASSERT_TRUE(fake_upstream_connection->write("bad protocol data!"));
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
codec_client_->waitForDisconnect();
EXPECT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().Status()->value().getStringView());
}
TEST_P(IntegrationTest, TestHead) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
Http::TestHeaderMapImpl head_request{{":method", "HEAD"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}};
// Without an explicit content length, assume we chunk for HTTP/1.1
auto response = sendRequestAndWaitForResponse(head_request, 0, default_response_headers_, 0);
ASSERT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
EXPECT_EQ(response->headers().ContentLength(), nullptr);
EXPECT_THAT(response->headers(),
HeaderValueOf(Headers::get().TransferEncoding,
Http::Headers::get().TransferEncodingValues.Chunked));
EXPECT_EQ(0, response->body().size());
// Preserve explicit content length.
Http::TestHeaderMapImpl content_length_response{{":status", "200"}, {"content-length", "12"}};
response = sendRequestAndWaitForResponse(head_request, 0, content_length_response, 0);
ASSERT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
EXPECT_THAT(response->headers(), HeaderValueOf(Headers::get().ContentLength, "12"));
EXPECT_EQ(response->headers().TransferEncoding(), nullptr);
EXPECT_EQ(0, response->body().size());
cleanupUpstreamAndDownstream();
}
// The Envoy HTTP/1.1 codec ASSERTs that T-E headers are cleared in
// encodeHeaders, so to test upstreams explicitly sending T-E: chunked we have
// to send raw HTTP.
TEST_P(IntegrationTest, TestHeadWithExplicitTE) {
initialize();
auto tcp_client = makeTcpConnection(lookupPort("http"));
tcp_client->write("HEAD / HTTP/1.1\r\nHost: host\r\n\r\n");
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
std::string data;
ASSERT_TRUE(fake_upstream_connection->waitForData(
FakeRawConnection::waitForInexactMatch("\r\n\r\n"), &data));
ASSERT_TRUE(
fake_upstream_connection->write("HTTP/1.1 200 OK\r\nTransfer-encoding: chunked\r\n\r\n"));
tcp_client->waitForData("\r\n\r\n", false);
std::string response = tcp_client->data();
EXPECT_THAT(response, HasSubstr("HTTP/1.1 200 OK\r\n"));
EXPECT_THAT(response, Not(HasSubstr("content-length")));
EXPECT_THAT(response, HasSubstr("transfer-encoding: chunked\r\n"));
EXPECT_THAT(response, EndsWith("\r\n\r\n"));
ASSERT_TRUE(fake_upstream_connection->close());
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
tcp_client->close();
}
TEST_P(IntegrationTest, TestBind) {
std::string address_string;
if (GetParam() == Network::Address::IpVersion::v4) {
address_string = TestUtility::getIpv4Loopback();
} else {
address_string = "::1";
}
config_helper_.setSourceAddress(address_string);
useAccessLog("%UPSTREAM_LOCAL_ADDRESS%\n");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
codec_client_->makeRequestWithBody(Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}},
1024);
ASSERT_TRUE(fake_upstreams_[0]->waitForHttpConnection(*dispatcher_, fake_upstream_connection_));
ASSERT_NE(fake_upstream_connection_, nullptr);
std::string address =
fake_upstream_connection_->connection().remoteAddress()->ip()->addressAsString();
EXPECT_EQ(address, address_string);
ASSERT_TRUE(fake_upstream_connection_->waitForNewStream(*dispatcher_, upstream_request_));
ASSERT_NE(upstream_request_, nullptr);
ASSERT_TRUE(upstream_request_->waitForEndStream(*dispatcher_));
cleanupUpstreamAndDownstream();
EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr(address_string));
}
TEST_P(IntegrationTest, TestFailedBind) {
config_helper_.setSourceAddress("8.8.8.8");
initialize();
// Envoy will create and close some number of connections when trying to bind.
// Make sure they don't cause assertion failures when we ignore them.
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
codec_client_ = makeHttpConnection(lookupPort("http"));
// With no ability to successfully bind on an upstream connection Envoy should
// send a 500.
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"},
{"x-forwarded-for", "10.0.0.1"},
{"x-envoy-upstream-rq-timeout-ms", "1000"}});
response->waitForEndStream();
EXPECT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("503"));
EXPECT_LT(0, test_server_->counter("cluster.cluster_0.bind_errors")->value());
}
ConfigHelper::HttpModifierFunction setVia(const std::string& via) {
return
[via](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) { hcm.set_via(via); };
}
// Validate in a basic header-only request we get via header insertion.
TEST_P(IntegrationTest, ViaAppendHeaderOnly) {
config_helper_.addConfigModifier(setVia("bar"));
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":authority", "host"},
{"via", "foo"},
{"connection", "close"}});
waitForNextUpstreamRequest();
EXPECT_THAT(upstream_request_->headers(), HeaderValueOf(Headers::get().Via, "foo, bar"));
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
response->waitForEndStream();
codec_client_->waitForDisconnect();
EXPECT_TRUE(response->complete());
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
EXPECT_THAT(response->headers(), HeaderValueOf(Headers::get().Via, "bar"));
}
// Validate that 100-continue works as expected with via header addition on both request and
// response path.
TEST_P(IntegrationTest, ViaAppendWith100Continue) {
config_helper_.addConfigModifier(setVia("foo"));
testEnvoyHandling100Continue(false, "foo");
}
// Test delayed close semantics for downstream HTTP/1.1 connections. When an early response is
// sent by Envoy, it will wait for response acknowledgment (via FIN/RST) from the client before
// closing the socket (with a timeout for ensuring cleanup).
TEST_P(IntegrationTest, TestDelayedConnectionTeardownOnGracefulClose) {
// This test will trigger an early 413 Payload Too Large response due to buffer limits being
// exceeded. The following filter is needed since the router filter will never trigger a 413.
config_helper_.addFilter("{ name: encoder-decoder-buffer-filter, typed_config: { \"@type\": "
"type.googleapis.com/google.protobuf.Empty } }");
config_helper_.setBufferLimits(1024, 1024);
initialize();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_client_->sendData(*request_encoder_, 1024 * 65, false);
response->waitForEndStream();
EXPECT_TRUE(response->complete());
EXPECT_EQ("413", response->headers().Status()->value().getStringView());
// With no delayed close processing, Envoy will close the connection immediately after flushing
// and this should instead return true.
EXPECT_FALSE(codec_client_->waitForDisconnect(std::chrono::milliseconds(500)));
// Issue a local close and check that the client did not pick up a remote close which can happen
// when delayed close semantics are disabled.
codec_client_->connection()->close(Network::ConnectionCloseType::NoFlush);
EXPECT_EQ(codec_client_->lastConnectionEvent(), Network::ConnectionEvent::LocalClose);
}
// Test configuration of the delayed close timeout on downstream HTTP/1.1 connections. A value of 0
// disables delayed close processing.