Skip to content

Commit

Permalink
cherry-pick of envoyproxy#13683 (#280)
Browse files Browse the repository at this point in the history
Signed-off-by: Kuat Yessenov <kuat@google.com>
  • Loading branch information
kyessenov authored Oct 28, 2020
1 parent cdbfe70 commit e5a3c35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/common/router/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
if (direct_response != nullptr) {
config_.stats_.rq_direct_response_.inc();
direct_response->rewritePathHeader(headers, !config_.suppress_envoy_headers_);
callbacks_->streamInfo().setRouteName(direct_response->routeName());
callbacks_->sendLocalReply(
direct_response->responseCode(), direct_response->responseBody(),
[this, direct_response,
Expand All @@ -392,7 +393,6 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
direct_response->finalizeResponseHeaders(response_headers, callbacks_->streamInfo());
},
absl::nullopt, StreamInfo::ResponseCodeDetails::get().DirectResponse);
callbacks_->streamInfo().setRouteName(direct_response->routeName());
return Http::FilterHeadersStatus::StopIteration;
}

Expand Down
6 changes: 6 additions & 0 deletions test/integration/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ TEST_P(IntegrationTest, RouterDirectResponseWithBody) {
}

TEST_P(IntegrationTest, RouterDirectResponseEmptyBody) {
useAccessLog("%ROUTE_NAME%");
static const std::string domain("direct.example.com");
static const std::string prefix("/");
static const Http::Code status(Http::Code::OK);
static const std::string route_name("direct_response_route");
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void {
Expand All @@ -215,6 +217,7 @@ TEST_P(IntegrationTest, RouterDirectResponseEmptyBody) {
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)->set_name(route_name);
});
initialize();

Expand All @@ -230,6 +233,9 @@ TEST_P(IntegrationTest, RouterDirectResponseEmptyBody) {
EXPECT_EQ(nullptr, response->headers().ContentType());
// Content-length header is correct.
EXPECT_EQ("0", response->headers().getContentLengthValue());

std::string log = waitForAccessLog(access_log_name_);
EXPECT_THAT(log, HasSubstr(route_name));
}

TEST_P(IntegrationTest, ConnectionClose) {
Expand Down

0 comments on commit e5a3c35

Please sign in to comment.