-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
protocol_integration_test.cc
5482 lines (4755 loc) · 245 KB
/
protocol_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 "protocol_integration_test.h"
#include "test/integration/protocol_integration_test.h"
#include <functional>
#include <list>
#include <memory>
#include <regex>
#include <string>
#include <vector>
#include "envoy/buffer/buffer.h"
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/route/v3/route_components.pb.h"
#include "envoy/event/dispatcher.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "envoy/http/header_map.h"
#include "envoy/registry/registry.h"
#include "source/common/api/api_impl.h"
#include "source/common/buffer/buffer_impl.h"
#include "source/common/common/fmt.h"
#include "source/common/common/thread_annotations.h"
#include "source/common/http/headers.h"
#include "source/common/http/utility.h"
#include "source/common/network/utility.h"
#include "source/common/protobuf/utility.h"
#include "source/common/runtime/runtime_impl.h"
#include "source/common/upstream/upstream_impl.h"
#include "test/common/http/http2/http2_frame.h"
#include "test/common/upstream/utility.h"
#include "test/integration/autonomous_upstream.h"
#include "test/integration/http_integration.h"
#include "test/integration/socket_interface_swap.h"
#include "test/integration/test_host_predicate_config.h"
#include "test/integration/utility.h"
#include "test/mocks/upstream/retry_priority.h"
#include "test/mocks/upstream/retry_priority_factory.h"
#include "test/test_common/environment.h"
#include "test/test_common/logging.h"
#include "test/test_common/network_utility.h"
#include "test/test_common/registry.h"
#include "test/test_common/threadsafe_singleton_injector.h"
#include "absl/time/time.h"
#include "gtest/gtest.h"
using testing::HasSubstr;
using testing::Not;
namespace Envoy {
void setDoNotValidateRouteConfig(
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& hcm) {
auto* route_config = hcm.mutable_route_config();
route_config->mutable_validate_clusters()->set_value(false);
};
TEST_P(ProtocolIntegrationTest, TrailerSupportHttp1) {
config_helper_.addConfigModifier(setEnableDownstreamTrailersHttp1());
config_helper_.addConfigModifier(setEnableUpstreamTrailersHttp1());
testTrailers(10, 20, true, true);
}
TEST_P(ProtocolIntegrationTest, ShutdownWithActiveConnPoolConnections) {
auto response = makeHeaderOnlyRequest(nullptr, 0);
// Shut down the server with active connection pool connections.
test_server_.reset();
checkSimpleRequestSuccess(0U, 0U, response.get());
}
TEST_P(ProtocolIntegrationTest, LogicalDns) {
if (use_universal_header_validator_) {
// TODO(#27132): auto_host_rewrite is broken for IPv6 and is failing UHV validation
return;
}
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
RELEASE_ASSERT(bootstrap.mutable_static_resources()->clusters_size() == 1, "");
auto& cluster = *bootstrap.mutable_static_resources()->mutable_clusters(0);
cluster.set_type(envoy::config::cluster::v3::Cluster::LOGICAL_DNS);
cluster.set_dns_lookup_family(envoy::config::cluster::v3::Cluster::ALL);
});
config_helper_.addConfigModifier(
[](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) {
auto* route = hcm.mutable_route_config()->mutable_virtual_hosts(0)->mutable_routes(0);
route->mutable_route()->mutable_auto_host_rewrite()->set_value(true);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
sendRequestAndWaitForResponse(default_request_headers_, 0, default_response_headers_, 0);
ASSERT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
}
TEST_P(ProtocolIntegrationTest, StrictDns) {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
RELEASE_ASSERT(bootstrap.mutable_static_resources()->clusters_size() == 1, "");
auto& cluster = *bootstrap.mutable_static_resources()->mutable_clusters(0);
cluster.set_type(envoy::config::cluster::v3::Cluster::STRICT_DNS);
cluster.set_dns_lookup_family(envoy::config::cluster::v3::Cluster::ALL);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
sendRequestAndWaitForResponse(default_request_headers_, 0, default_response_headers_, 0);
ASSERT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
}
// Change the default route to be restrictive, and send a request to an alternate route.
TEST_P(DownstreamProtocolIntegrationTest, RouterNotFound) { testRouterNotFound(); }
TEST_P(ProtocolIntegrationTest, RouterVirtualClusters) { testRouterVirtualClusters(); }
TEST_P(ProtocolIntegrationTest, RouterStats) { testRouteStats(); }
// Change the default route to be restrictive, and send a POST to an alternate route.
TEST_P(DownstreamProtocolIntegrationTest, RouterNotFoundBodyNoBuffer) {
testRouterNotFoundWithBody();
}
// Add a route that uses unknown cluster (expect 404 Not Found).
TEST_P(DownstreamProtocolIntegrationTest, RouterClusterNotFound404) {
config_helper_.addConfigModifier(&setDoNotValidateRouteConfig);
config_helper_.addConfigModifier(configureProxyStatus());
auto host = config_helper_.createVirtualHost("foo.lyft.com", "/unknown", "unknown_cluster");
host.mutable_routes(0)->mutable_route()->set_cluster_not_found_response_code(
envoy::config::route::v3::RouteAction::NOT_FOUND);
config_helper_.addVirtualHost(host);
initialize();
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("http"), "GET", "/unknown", "", downstream_protocol_, version_, "foo.lyft.com");
ASSERT_TRUE(response->complete());
EXPECT_EQ("404", response->headers().getStatusValue());
EXPECT_EQ(response->headers().getProxyStatusValue(),
"envoy; error=destination_unavailable; details=\"cluster_not_found; NC\"");
}
TEST_P(DownstreamProtocolIntegrationTest, TestHostWhitespacee) {
disable_client_header_validation_ = true;
config_helper_.addConfigModifier(&setDoNotValidateRouteConfig);
auto host = config_helper_.createVirtualHost("foo.lyft.com", "/unknown", "unknown_cluster");
host.mutable_routes(0)->mutable_route()->set_cluster_not_found_response_code(
envoy::config::route::v3::RouteAction::NOT_FOUND);
config_helper_.addVirtualHost(host);
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder = codec_client_->startRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":authority", " foo.lyft.com "}, {":path", "/unknown"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
// For HTTP/1 the whitespace will be stripped, and 404 returned as above.
if (downstreamProtocol() == Http::CodecType::HTTP1) {
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("404", response->headers().getStatusValue());
EXPECT_TRUE(response->complete());
} else {
// For HTTP/2 and above, the whitespace is illegal.
ASSERT_TRUE(response->waitForReset());
ASSERT_TRUE(codec_client_->waitForDisconnect());
}
}
// Add a route that uses unknown cluster (expect 503 Service Unavailable).
TEST_P(DownstreamProtocolIntegrationTest, RouterClusterNotFound503) {
config_helper_.addConfigModifier(&setDoNotValidateRouteConfig);
auto host = config_helper_.createVirtualHost("foo.lyft.com", "/unknown", "unknown_cluster");
host.mutable_routes(0)->mutable_route()->set_cluster_not_found_response_code(
envoy::config::route::v3::RouteAction::SERVICE_UNAVAILABLE);
config_helper_.addVirtualHost(host);
initialize();
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("http"), "GET", "/unknown", "", downstream_protocol_, version_, "foo.lyft.com");
ASSERT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().getStatusValue());
}
// Add a route which redirects HTTP to HTTPS, and verify Envoy sends a 301
TEST_P(DownstreamProtocolIntegrationTest, RouterRedirectHttpRequest) {
autonomous_upstream_ = true;
useAccessLog("%DOWNSTREAM_WIRE_BYTES_SENT% %DOWNSTREAM_WIRE_BYTES_RECEIVED% "
"%DOWNSTREAM_HEADER_BYTES_SENT% %DOWNSTREAM_HEADER_BYTES_RECEIVED%");
auto host = config_helper_.createVirtualHost("www.redirect.com", "/");
host.set_require_tls(envoy::config::route::v3::VirtualHost::ALL);
config_helper_.addVirtualHost(host);
initialize();
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("http"), "GET", "/foo", "", downstream_protocol_, version_, "www.redirect.com");
ASSERT_TRUE(response->complete());
if (downstream_protocol_ <= Http::CodecType::HTTP2) {
EXPECT_EQ("301", response->headers().getStatusValue());
EXPECT_EQ("https://www.redirect.com/foo",
response->headers().get(Http::Headers::get().Location)[0]->value().getStringView());
expectDownstreamBytesSentAndReceived(BytesCountExpectation(145, 45, 111, 23),
BytesCountExpectation(69, 30, 69, 30),
BytesCountExpectation(0, 30, 0, 30));
} else {
// All QUIC requests use https, and should not be redirected. (Even those sent with http scheme
// will be overridden to https by HCM.)
EXPECT_EQ("200", response->headers().getStatusValue());
}
}
TEST_P(ProtocolIntegrationTest, UnknownResponsecode) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
Http::TestResponseHeaderMapImpl response_headers{{":status", "600"}};
auto response = sendRequestAndWaitForResponse(default_request_headers_, 0, response_headers, 0);
// Regression test https://github.com/envoyproxy/envoy/issues/14890 - no content-length added.
EXPECT_EQ(upstream_request_->headers().ContentLength(), nullptr);
ASSERT_TRUE(response->complete());
EXPECT_EQ("600", response->headers().getStatusValue());
}
TEST_P(DownstreamProtocolIntegrationTest, AddInvalidDecodedData) {
EXPECT_ENVOY_BUG(
{
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter(R"EOF(
name: add-invalid-data-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("502", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_),
HasSubstr("filter_added_invalid_request_data"));
},
"Invalid request data");
}
TEST_P(DownstreamProtocolIntegrationTest, AddInvalidEncodedData) {
EXPECT_ENVOY_BUG(
{
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter(R"EOF(
name: add-invalid-data-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
default_request_headers_.setCopy(Envoy::Http::LowerCaseString("invalid-encode"), "yes");
auto encoder_decoder = codec_client_->startRequest(default_request_headers_);
auto response = std::move(encoder_decoder.second);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("502", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_),
HasSubstr("filter_added_invalid_response_data"));
cleanupUpstreamAndDownstream();
},
"Invalid response data");
}
// Verifies behavior for https://github.com/envoyproxy/envoy/pull/11248
TEST_P(ProtocolIntegrationTest, AddBodyToRequestAndWaitForIt) {
config_helper_.prependFilter(R"EOF(
name: wait-for-whole-request-and-response-filter
)EOF");
config_helper_.prependFilter(R"EOF(
name: add-body-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
EXPECT_EQ("body", upstream_request_->body().toString());
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, false);
// encode data, as we have a separate test for the transforming header only response.
upstream_request_->encodeData(128, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
}
TEST_P(ProtocolIntegrationTest, DEPRECATED_FEATURE_TEST(RouterOnlyTracing)) {
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
envoy::extensions::filters::http::router::v3::Router router_config;
router_config.set_start_child_span(true);
hcm.mutable_http_filters(0)->mutable_typed_config()->PackFrom(router_config);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
sendRequestAndWaitForResponse(default_request_headers_, 0, default_response_headers_, 0);
}
TEST_P(ProtocolIntegrationTest, AddBodyToResponseAndWaitForIt) {
config_helper_.prependFilter(R"EOF(
name: add-body-filter
)EOF");
config_helper_.prependFilter(R"EOF(
name: wait-for-whole-request-and-response-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 128);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ("body", response->body());
}
TEST_P(ProtocolIntegrationTest, ContinueHeadersOnlyInjectBodyFilter) {
config_helper_.prependFilter(R"EOF(
name: continue-headers-only-inject-body-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Send a headers only request.
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
// Make sure that the body was injected to the request.
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(upstream_request_->receivedData());
EXPECT_EQ(upstream_request_->body().toString(), "body");
// Send a headers only response.
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response->waitForEndStream());
// Make sure that the body was injected to the response.
EXPECT_TRUE(response->complete());
EXPECT_EQ(response->body(), "body");
}
TEST_P(ProtocolIntegrationTest, StopIterationHeadersInjectBodyFilter) {
config_helper_.prependFilter(R"EOF(
name: stop-iteration-headers-inject-body-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Send a headers only request.
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
// Make sure that the body was injected to the request.
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(upstream_request_->receivedData());
EXPECT_EQ(upstream_request_->body().toString(), "body");
// Send a headers only response.
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response->waitForEndStream());
// Make sure that the body was injected to the response.
EXPECT_TRUE(response->complete());
EXPECT_EQ(response->body(), "body");
}
TEST_P(ProtocolIntegrationTest, AddEncodedTrailers) {
config_helper_.prependFilter(R"EOF(
name: add-trailers-filter
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 128);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "503"}}, false);
upstream_request_->encodeData(128, true);
ASSERT_TRUE(response->waitForEndStream());
if (upstreamProtocol() != Http::CodecType::HTTP1) {
EXPECT_EQ("decode", upstream_request_->trailers()
->get(Http::LowerCaseString("grpc-message"))[0]
->value()
.getStringView());
}
EXPECT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().getStatusValue());
if (downstream_protocol_ != Http::CodecType::HTTP1) {
EXPECT_EQ("encode", response->trailers()->getGrpcMessageValue());
}
}
TEST_P(ProtocolIntegrationTest, MixedCaseScheme) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
default_request_headers_.setScheme("Http");
auto response =
sendRequestAndWaitForResponse(default_request_headers_, 0, default_response_headers_, 0);
auto scheme = upstream_request_->headers().getSchemeValue();
EXPECT_TRUE(scheme.empty() || scheme == "http");
}
TEST_P(ProtocolIntegrationTest, AccessLogOnRequestStartTest) {
if (upstreamProtocol() == Http::CodecType::HTTP3) {
return;
}
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
hcm.mutable_access_log_options()->set_flush_access_log_on_new_request(true);
});
useAccessLog("%RESPONSE_CODE% %ACCESS_LOG_TYPE%");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":path", "/test"}, {":scheme", "http"}, {":authority", "host.com"}});
waitForNextUpstreamRequest();
EXPECT_EQ(absl::StrCat("0 ", AccessLogType_Name(AccessLog::AccessLogType::DownstreamStart)),
waitForAccessLog(access_log_name_, 0, true));
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ(absl::StrCat("200 ", AccessLogType_Name(AccessLog::AccessLogType::DownstreamEnd)),
waitForAccessLog(access_log_name_, 1, true));
}
TEST_P(ProtocolIntegrationTest, PeriodicAccessLog) {
if (upstreamProtocol() == Http::CodecType::HTTP3) {
return;
}
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
hcm.mutable_access_log_options()->mutable_access_log_flush_interval()->set_nanos(
100000000); // 0.1 seconds
});
useAccessLog("%ACCESS_LOG_TYPE%");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":path", "/test"}, {":scheme", "http"}, {":authority", "host.com"}});
waitForNextUpstreamRequest();
EXPECT_EQ(AccessLogType_Name(AccessLog::AccessLogType::DownstreamPeriodic),
waitForAccessLog(access_log_name_, 0, true));
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
}
// Regression test for https://github.com/envoyproxy/envoy/issues/9873
TEST_P(ProtocolIntegrationTest, ResponseWithHostHeader) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(
Http::TestResponseHeaderMapImpl{{":status", "200"}, {"host", "host"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ("host",
response->headers().get(Http::LowerCaseString("host"))[0]->value().getStringView());
}
// Upstream 304 response with Content-Length and no actual body
// The content-length header should be preserved and no transfer-encoding header should be added
TEST_P(ProtocolIntegrationTest, Upstream304ResponseWithContentLength) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"if-none-match", "\"1234567890\""}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "304"},
{"etag", "\"1234567890\""},
{"content-length", "123"}},
true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("304", response->headers().getStatusValue());
EXPECT_EQ(
"123",
response->headers().get(Http::LowerCaseString("content-length"))[0]->value().getStringView());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("transfer-encoding")).empty());
// Make a HEAD request to make sure the previous 304 response with Content-Length did not cause
// issue.
response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "HEAD"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"if-none-match", "\"1234567890\""}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "304"},
{"etag", "\"1234567890\""},
{"content-length", "123"}},
true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("304", response->headers().getStatusValue());
EXPECT_EQ(
"123",
response->headers().get(Http::LowerCaseString("content-length"))[0]->value().getStringView());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("transfer-encoding")).empty());
}
// Upstream 304 response without Content-Length
// No content-length nor transfer-encoding header should be added for all protocol combinations.
TEST_P(ProtocolIntegrationTest, 304ResponseWithoutContentLength) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"if-none-match", "\"1234567890\""}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(
Http::TestResponseHeaderMapImpl{{":status", "304"}, {"etag", "\"1234567890\""}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("304", response->headers().getStatusValue());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("transfer-encoding")).empty());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("content-length")).empty());
}
// Upstream 304 response for HEAD request without Content-Length
// Response to HEAD request is the same as response to GET request and consistent with different
// protocol combinations.
TEST_P(ProtocolIntegrationTest, 304HeadResponseWithoutContentLength) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "HEAD"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"if-none-match", "\"1234567890\""}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(
Http::TestResponseHeaderMapImpl{{":status", "304"}, {"etag", "\"1234567890\""}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("304", response->headers().getStatusValue());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("transfer-encoding")).empty());
EXPECT_TRUE(response->headers().get(Http::LowerCaseString("content-length")).empty());
}
// Tests that the response to a HEAD request can have content-length header but empty body.
TEST_P(ProtocolIntegrationTest, 200HeadResponseWithContentLength) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "HEAD"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"if-none-match", "\"1234567890\""}});
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(
Http::TestResponseHeaderMapImpl{{":status", "200"}, {"content-length", "123"}}, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ(
"123",
response->headers().get(Http::LowerCaseString("content-length"))[0]->value().getStringView());
}
// Tests missing headers needed for H/1 codec first line.
TEST_P(DownstreamProtocolIntegrationTest, DownstreamRequestWithFaultyFilter) {
if (upstreamProtocol() == Http::CodecType::HTTP3) {
// For QUIC, even through the headers are not sent upstream, the stream will
// be created. Use the autonomous upstream and allow incomplete streams.
autonomous_allow_incomplete_streams_ = true;
autonomous_upstream_ = true;
}
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"}});
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_), testing::MatchesRegex(".*required.*header.*"));
// Missing path for non-CONNECT
response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-path", "yes"}});
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_, 1), testing::MatchesRegex(".*required.*header.*"));
}
TEST_P(DownstreamProtocolIntegrationTest, FaultyFilterWithConnect) {
if (upstreamProtocol() == Http::CodecType::HTTP3) {
// For QUIC, even through the headers are not sent upstream, the stream will
// be created. Use the autonomous upstream and allow incomplete streams.
autonomous_allow_incomplete_streams_ = true;
autonomous_upstream_ = true;
}
// Faulty filter that removed host in a CONNECT request.
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
ConfigHelper::setConnectConfig(hcm, false, false,
downstreamProtocol() == Http::CodecType::HTTP3);
});
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing host for CONNECT
auto headers = Http::TestRequestHeaderMapImpl{
{":method", "CONNECT"}, {":scheme", "http"}, {":authority", "www.host.com:80"}};
auto encoder_decoder = codec_client_->startRequest(headers);
auto response = std::move(encoder_decoder.second);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("503", response->headers().getStatusValue());
// With and without UHV the details string is different:
// non-UHV: filter_removed_required_request_headers{missing_required_header:_host}
// UHV: filter_removed_required_request_headers{header_validation_failed:_uhv.invalid_host}
EXPECT_THAT(waitForAccessLog(access_log_name_), testing::MatchesRegex(".*required.*header.*"));
// Wait to process STOP_SENDING on the client for quic.
if (downstreamProtocol() == Http::CodecType::HTTP3) {
EXPECT_TRUE(response->waitForReset());
}
}
TEST_P(DownstreamProtocolIntegrationTest, MissingHeadersLocalReply) {
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"},
{"send-reply", "yes"}});
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("invalid_header_filter_ready"));
}
TEST_P(DownstreamProtocolIntegrationTest, MissingHeadersLocalReplyDownstreamBytesCount) {
useAccessLog("%DOWNSTREAM_WIRE_BYTES_SENT% %DOWNSTREAM_WIRE_BYTES_RECEIVED% "
"%DOWNSTREAM_HEADER_BYTES_SENT% %DOWNSTREAM_HEADER_BYTES_RECEIVED%");
config_helper_.addFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"},
{"send-reply", "yes"}});
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
expectDownstreamBytesSentAndReceived(BytesCountExpectation(90, 88, 71, 54),
BytesCountExpectation(40, 58, 40, 58),
BytesCountExpectation(7, 10, 7, 8));
}
TEST_P(DownstreamProtocolIntegrationTest, MissingHeadersLocalReplyUpstreamBytesCount) {
useAccessLog("%UPSTREAM_WIRE_BYTES_SENT% %UPSTREAM_WIRE_BYTES_RECEIVED% "
"%UPSTREAM_HEADER_BYTES_SENT% %UPSTREAM_HEADER_BYTES_RECEIVED%");
config_helper_.addFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"},
{"send-reply", "yes"}});
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
expectUpstreamBytesSentAndReceived(BytesCountExpectation(0, 0, 0, 0),
BytesCountExpectation(0, 0, 0, 0),
BytesCountExpectation(0, 0, 0, 0));
}
TEST_P(DownstreamProtocolIntegrationTest, MissingHeadersLocalReplyWithBody) {
useAccessLog("%RESPONSE_CODE_DETAILS%");
config_helper_.prependFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeRequestWithBody(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"},
{"send-reply", "yes"}},
1024);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("invalid_header_filter_ready"));
}
TEST_P(DownstreamProtocolIntegrationTest, MissingHeadersLocalReplyWithBodyBytesCount) {
useAccessLog("%DOWNSTREAM_WIRE_BYTES_SENT% %DOWNSTREAM_WIRE_BYTES_RECEIVED% "
"%DOWNSTREAM_HEADER_BYTES_SENT% %DOWNSTREAM_HEADER_BYTES_RECEIVED%");
config_helper_.addFilter("{ name: invalid-header-filter }");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
// Missing method
auto response = codec_client_->makeRequestWithBody(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"remove-method", "yes"},
{"send-reply", "yes"}},
1024);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
expectDownstreamBytesSentAndReceived(BytesCountExpectation(109, 1152, 90, 81),
BytesCountExpectation(0, 58, 0, 58),
BytesCountExpectation(7, 10, 7, 8));
}
TEST_P(DownstreamProtocolIntegrationTest, TeSanitization) {
if (downstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
autonomous_upstream_ = true;
default_request_headers_.setTE("gzip");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
auto upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_[0].get())->lastRequestHeaders();
EXPECT_TRUE(upstream_headers != nullptr);
EXPECT_EQ("", upstream_headers->getTEValue());
}
TEST_P(DownstreamProtocolIntegrationTest, TeSanitizationTrailers) {
if (downstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
autonomous_upstream_ = true;
default_request_headers_.setTE("trailers");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
auto upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_[0].get())->lastRequestHeaders();
EXPECT_TRUE(upstream_headers != nullptr);
EXPECT_EQ("trailers", upstream_headers->getTEValue());
}
TEST_P(DownstreamProtocolIntegrationTest, TeSanitizationTrailersMultipleValuesAndWeigthted) {
if (downstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
autonomous_upstream_ = true;
default_request_headers_.setTE("chunked;q=0.8 , trailers ,deflate ");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
auto upstream_headers =
reinterpret_cast<AutonomousUpstream*>(fake_upstreams_[0].get())->lastRequestHeaders();
EXPECT_TRUE(upstream_headers != nullptr);
EXPECT_EQ("trailers", upstream_headers->getTEValue());
}
// Regression test for https://github.com/envoyproxy/envoy/issues/10270
TEST_P(ProtocolIntegrationTest, LongHeaderValueWithSpaces) {
// Header with at least 20kb of spaces surrounded by non-whitespace characters to ensure that
// dispatching is split across 2 dispatch calls. This threshold comes from Envoy preferring 16KB
// reads, which the buffer rounds up to about 20KB when allocating slices in
// Buffer::OwnedImpl::reserve().
const std::string long_header_value_with_inner_lws = "v" + std::string(32 * 1024, ' ') + "v";
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"longrequestvalue", long_header_value_with_inner_lws}});
waitForNextUpstreamRequest();
EXPECT_EQ(long_header_value_with_inner_lws, upstream_request_->headers()
.get(Http::LowerCaseString("longrequestvalue"))[0]
->value()
.getStringView());
upstream_request_->encodeHeaders(
Http::TestResponseHeaderMapImpl{{":status", "200"},
{"host", "host"},
{"longresponsevalue", long_header_value_with_inner_lws}},
true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ("host",
response->headers().get(Http::LowerCaseString("host"))[0]->value().getStringView());
EXPECT_EQ(long_header_value_with_inner_lws,
response->headers()
.get(Http::LowerCaseString("longresponsevalue"))[0]
->value()
.getStringView());
}
TEST_P(ProtocolIntegrationTest, Retry) {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
RELEASE_ASSERT(bootstrap.mutable_static_resources()->clusters_size() == 1, "");
auto& cluster = *bootstrap.mutable_static_resources()->mutable_clusters(0);
cluster.mutable_track_cluster_stats()->set_request_response_sizes(true);
});
useAccessLog("%UPSTREAM_WIRE_BYTES_SENT% %UPSTREAM_WIRE_BYTES_RECEIVED% "
"%UPSTREAM_HEADER_BYTES_SENT% %UPSTREAM_HEADER_BYTES_RECEIVED%");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(
Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"x-forwarded-for", "10.0.0.1"},
{"x-envoy-retry-on", "5xx"}},
1024);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "503"}}, false);
if (fake_upstreams_[0]->httpType() == Http::CodecType::HTTP1) {
ASSERT_TRUE(fake_upstream_connection_->waitForDisconnect());
ASSERT_TRUE(fake_upstreams_[0]->waitForHttpConnection(*dispatcher_, fake_upstream_connection_,
std::chrono::milliseconds(500)));
} else {
ASSERT_TRUE(upstream_request_->waitForReset());
}
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(default_response_headers_, false);
upstream_request_->encodeData(512, true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(upstream_request_->complete());
EXPECT_EQ(1024U, upstream_request_->bodyLength());
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
EXPECT_EQ(512U, response->body().size());
Stats::Store& stats = test_server_->server().stats();
if (upstreamProtocol() == Http::CodecType::HTTP2) {
Stats::CounterSharedPtr counter = TestUtility::findCounter(
stats, absl::StrCat("cluster.cluster_0.", upstreamProtocolStatsRoot(), ".tx_reset"));
ASSERT_NE(nullptr, counter);
EXPECT_EQ(1L, counter->value());
}
EXPECT_NE(nullptr,
test_server_->counter(absl::StrCat("cluster.cluster_0.", upstreamProtocolStatsRoot(),
".dropped_headers_with_underscores")));
test_server_->waitUntilHistogramHasSamples("cluster.cluster_0.upstream_rq_headers_size");
test_server_->waitUntilHistogramHasSamples("cluster.cluster_0.upstream_rs_headers_size");
auto find_histo_sample_count = [&](const std::string& name) -> uint64_t {
for (auto& histogram : test_server_->histograms()) {
if (histogram->name() == name) {
return TestUtility::readSampleCount(test_server_->server().dispatcher(), *histogram);
}
}
return 0;
};
EXPECT_EQ(find_histo_sample_count("cluster.cluster_0.upstream_rq_headers_size"), 2);
EXPECT_EQ(find_histo_sample_count("cluster.cluster_0.upstream_rs_headers_size"), 2);
// The two requests are sent with https scheme rather than http for QUIC downstream.
const size_t quic_https_extra_bytes = (downstreamProtocol() == Http::CodecType::HTTP3 ? 2u : 0u);
const size_t http2_header_bytes_received =
(GetParam().http2_implementation == Http2Impl::Oghttp2) ? 24 : 27;
expectUpstreamBytesSentAndReceived(
BytesCountExpectation(2566 + quic_https_extra_bytes, 635, 430 + quic_https_extra_bytes, 54),
BytesCountExpectation(2262, 548, 196, http2_header_bytes_received),
BytesCountExpectation(2204, 520, 150, 6));
}
// Regression test to guarantee that buffering for retries and shadows doesn't double the body size.
// This test is actually irrelevant for QUIC, as this issue only shows up with header-only requests.
// QUIC will always send an empty data frame with FIN.
TEST_P(ProtocolIntegrationTest, RetryWithBuffer) {
config_helper_.prependFilter(R"EOF(
name: add-body-filter
typed_config:
"@type": type.googleapis.com/test.integration.filters.AddBodyFilterConfig
where_to_add_body: DEFAULT
)EOF");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeHeaderOnlyRequest(
Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"x-forwarded-for", "10.0.0.1"},
{"x-envoy-retry-on", "5xx"}});
waitForNextUpstreamRequest();
EXPECT_TRUE(upstream_request_->complete());
EXPECT_TRUE(upstream_request_->receivedData());
EXPECT_EQ(upstream_request_->bodyLength(), 4);
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response->waitForEndStream());
}
TEST_P(ProtocolIntegrationTest, RetryStreaming) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "sni.lyft.com"},
{"x-forwarded-for", "10.0.0.1"},
{"x-envoy-retry-on", "5xx"}});