From c18432ee6248a600ebe322b4f41ac5965755e9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Conte=20Mac=20Donell?= Date: Sat, 21 Oct 2023 09:44:50 -0700 Subject: [PATCH] connect_grpc_bridge: remove request content-length (#30363) We need to always remove Content-Length since the request on the other side of the filter is chunked with a different body size. Signed-off-by: Martin Conte Mac Donell --- .../extensions/filters/http/connect_grpc_bridge/filter.cc | 3 ++- .../connect_grpc_bridge_filter_test.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/extensions/filters/http/connect_grpc_bridge/filter.cc b/source/extensions/filters/http/connect_grpc_bridge/filter.cc index 0c8637c0c0d9..64f41ee8aac7 100644 --- a/source/extensions/filters/http/connect_grpc_bridge/filter.cc +++ b/source/extensions/filters/http/connect_grpc_bridge/filter.cc @@ -290,8 +290,9 @@ Http::FilterHeadersStatus ConnectGrpcBridgeFilter::decodeHeaders(Http::RequestHe unary_payload_frame_flags_ |= Envoy::Grpc::GRPC_FH_COMPRESSED; } + headers.removeContentLength(); + if (end_stream) { - headers.removeContentLength(); Grpc::Encoder().prependFrameHeader(unary_payload_frame_flags_, request_buffer_); decoder_callbacks_->addDecodedData(request_buffer_, true); } diff --git a/test/extensions/filters/http/connect_grpc_bridge/connect_grpc_bridge_filter_test.cc b/test/extensions/filters/http/connect_grpc_bridge/connect_grpc_bridge_filter_test.cc index 5892571619e2..2c99607397ca 100644 --- a/test/extensions/filters/http/connect_grpc_bridge/connect_grpc_bridge_filter_test.cc +++ b/test/extensions/filters/http/connect_grpc_bridge/connect_grpc_bridge_filter_test.cc @@ -450,6 +450,14 @@ TEST_F(ConnectGrpcBridgeFilterTest, UnaryRequestWithNoBodyNorTrailers) { EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, true)); } +TEST_F(ConnectGrpcBridgeFilterTest, UnaryRequestRemovesContentLength) { + request_headers_.setCopy(Http::CustomHeaders::get().ConnectProtocolVersion, "1"); + request_headers_.setContentType(Http::Headers::get().ContentTypeValues.Grpc); + request_headers_.setContentLength(1337); + EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false)); + EXPECT_EQ("", request_headers_.get_("content-length")); +} + TEST_F(ConnectGrpcBridgeFilterTest, StreamingSupportedContentType) { request_headers_.setContentType("application/connect+proto"); EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_.decodeHeaders(request_headers_, false));