From e5a3c358771977783a8ef2bf3a1000dc9b5e5d2a Mon Sep 17 00:00:00 2001 From: Kuat Date: Wed, 28 Oct 2020 12:36:43 -0700 Subject: [PATCH] cherry-pick of https://github.com/envoyproxy/envoy/pull/13683 (#280) Signed-off-by: Kuat Yessenov --- source/common/router/router.cc | 2 +- test/integration/integration_test.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/common/router/router.cc b/source/common/router/router.cc index 5e6702c3cb75..6604f9b6a986 100644 --- a/source/common/router/router.cc +++ b/source/common/router/router.cc @@ -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, @@ -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; } diff --git a/test/integration/integration_test.cc b/test/integration/integration_test.cc index 594f5ac656c5..1037cad075bc 100644 --- a/test/integration/integration_test.cc +++ b/test/integration/integration_test.cc @@ -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 { @@ -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(status)); + virtual_host->mutable_routes(0)->set_name(route_name); }); initialize(); @@ -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) {