Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: set route name for direct response #13683

Merged
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
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_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit. const.

EXPECT_THAT(log, HasSubstr(route_name));
}

TEST_P(IntegrationTest, ConnectionClose) {
Expand Down