From da7be9bef76869395c5a3231b5694ad8e3e681c2 Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Mon, 17 May 2021 12:04:51 -0400 Subject: [PATCH 1/2] http: more tests for local reply and reset Signed-off-by: Alyssa Wilk --- .../filters/on_local_reply_filter.cc | 17 +++++++++++++++-- .../integration/multiplexed_integration_test.cc | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test/integration/filters/on_local_reply_filter.cc b/test/integration/filters/on_local_reply_filter.cc index 2bb2923d3c731..9ae70eafe6267 100644 --- a/test/integration/filters/on_local_reply_filter.cc +++ b/test/integration/filters/on_local_reply_filter.cc @@ -16,11 +16,23 @@ class OnLocalReplyFilter : public Http::PassThroughFilter { if (!request_headers.get(Http::LowerCaseString("reset")).empty()) { reset_ = true; } - decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "body", nullptr, absl::nullopt, - "details"); + if (!request_headers.get(Http::LowerCaseString("dual-local-reply")).empty()) { + dual_reply_ = true; + } + decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "original_reply", nullptr, absl::nullopt, + "original_reply"); return Http::FilterHeadersStatus::StopIteration; } + Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap&, bool) override { + if (dual_reply_) { + decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "second_reply", nullptr, absl::nullopt, + "second_reply"); + return Http::FilterHeadersStatus::StopIteration; + } + return Http::FilterHeadersStatus::Continue; + } + Http::LocalErrorStatus onLocalReply(const LocalReplyData&) override { if (reset_) { return Http::LocalErrorStatus::ContinueAndResetStream; @@ -29,6 +41,7 @@ class OnLocalReplyFilter : public Http::PassThroughFilter { } bool reset_{}; + bool dual_reply_{}; }; class OnLocalReplyFilterConfig : public Extensions::HttpFilters::Common::EmptyHttpFilterConfig { diff --git a/test/integration/multiplexed_integration_test.cc b/test/integration/multiplexed_integration_test.cc index 433790b46d7dd..233b21299f225 100644 --- a/test/integration/multiplexed_integration_test.cc +++ b/test/integration/multiplexed_integration_test.cc @@ -1781,11 +1781,27 @@ TEST_P(Http2IntegrationTest, OnLocalReply) { initialize(); codec_client_ = makeHttpConnection(lookupPort("http")); + // The filter will send a local reply when receiving headers, the client + // should get a complete response. { auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_); ASSERT_TRUE(response->waitForEndStream()); ASSERT_TRUE(response->complete()); + EXPECT_EQ("original_reply", response->body()); } + // The filter will send a local reply when receiving headers, and interrupt + // that with a second reply sent from the encoder chain. The client will see + // the second response. + { + default_request_headers_.addCopy("dual-local-reply", "yes"); + auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_); + ASSERT_TRUE(response->waitForEndStream()); + ASSERT_TRUE(response->complete()); + EXPECT_EQ("second_reply", response->body()); + } + // The filter will send a local reply when receiving headers and reset the + // stream onLocalReply. The client will get a reset and no response even if + // dual local replies are on (from the prior request). { default_request_headers_.addCopy("reset", "yes"); auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_); From 57a6bfb17bb9abb0cca995daaf0eeec67bcb7566 Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Mon, 17 May 2021 12:56:23 -0400 Subject: [PATCH 2/2] format Signed-off-by: Alyssa Wilk --- test/integration/filters/on_local_reply_filter.cc | 8 ++++---- test/integration/multiplexed_integration_test.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration/filters/on_local_reply_filter.cc b/test/integration/filters/on_local_reply_filter.cc index 9ae70eafe6267..c47f053903c65 100644 --- a/test/integration/filters/on_local_reply_filter.cc +++ b/test/integration/filters/on_local_reply_filter.cc @@ -19,15 +19,15 @@ class OnLocalReplyFilter : public Http::PassThroughFilter { if (!request_headers.get(Http::LowerCaseString("dual-local-reply")).empty()) { dual_reply_ = true; } - decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "original_reply", nullptr, absl::nullopt, - "original_reply"); + decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "original_reply", nullptr, + absl::nullopt, "original_reply"); return Http::FilterHeadersStatus::StopIteration; } Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap&, bool) override { if (dual_reply_) { - decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "second_reply", nullptr, absl::nullopt, - "second_reply"); + decoder_callbacks_->sendLocalReply(Http::Code::BadRequest, "second_reply", nullptr, + absl::nullopt, "second_reply"); return Http::FilterHeadersStatus::StopIteration; } return Http::FilterHeadersStatus::Continue; diff --git a/test/integration/multiplexed_integration_test.cc b/test/integration/multiplexed_integration_test.cc index 233b21299f225..ace6f2e96edaf 100644 --- a/test/integration/multiplexed_integration_test.cc +++ b/test/integration/multiplexed_integration_test.cc @@ -1800,7 +1800,7 @@ TEST_P(Http2IntegrationTest, OnLocalReply) { EXPECT_EQ("second_reply", response->body()); } // The filter will send a local reply when receiving headers and reset the - // stream onLocalReply. The client will get a reset and no response even if + // stream onLocalReply. The client will get a reset and no response even if // dual local replies are on (from the prior request). { default_request_headers_.addCopy("reset", "yes");