Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test/integration/filters/on_local_reply_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +41,7 @@ class OnLocalReplyFilter : public Http::PassThroughFilter {
}

bool reset_{};
bool dual_reply_{};
};

class OnLocalReplyFilterConfig : public Extensions::HttpFilters::Common::EmptyHttpFilterConfig {
Expand Down
16 changes: 16 additions & 0 deletions test/integration/multiplexed_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down