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

Add DOWNSTREAM_LOCAL_ADDRESS header variable #2487

Merged
merged 4 commits into from
Jan 31, 2018
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: 2 additions & 0 deletions RAW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ final version.
* Added support for [Squash microservices debugger](https://github.com/solo-io/squash).
:ref:`Squash <envoy_api_msg_filter.http.Squash>` allows debugging an incoming request to a microservice in the mesh.
* Added support for direct responses -- i.e., sending a preconfigured HTTP response without proxying anywhere.
* Added DOWNSTREAM_LOCAL_ADDRESS, DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT header formatters, and
DOWNSTREAM_LOCAL_ADDRESS access log formatter.
5 changes: 5 additions & 0 deletions source/common/access_log/access_log_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ RequestInfoFormatter::RequestInfoFormatter(const std::string& field_name) {
field_extractor_ = [](const RequestInfo::RequestInfo& request_info) {
return request_info.downstreamLocalAddress()->asString();
};
} else if (field_name == "DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT") {
field_extractor_ = [](const Envoy::RequestInfo::RequestInfo& request_info) {
return RequestInfo::Utility::formatDownstreamAddressNoPort(
*request_info.downstreamLocalAddress());
};
} else if (field_name == "DOWNSTREAM_REMOTE_ADDRESS") {
field_extractor_ = [](const RequestInfo::RequestInfo& request_info) {
return request_info.downstreamRemoteAddress()->asString();
Expand Down
9 changes: 9 additions & 0 deletions source/common/router/header_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ RequestInfoHeaderFormatter::RequestInfoHeaderFormatter(absl::string_view field_n
return RequestInfo::Utility::formatDownstreamAddressNoPort(
*request_info.downstreamRemoteAddress());
};
} else if (field_name == "DOWNSTREAM_LOCAL_ADDRESS") {
field_extractor_ = [](const RequestInfo::RequestInfo& request_info) {
return request_info.downstreamLocalAddress()->asString();
};
} else if (field_name == "DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT") {
field_extractor_ = [](const Envoy::RequestInfo::RequestInfo& request_info) {
return RequestInfo::Utility::formatDownstreamAddressNoPort(
*request_info.downstreamLocalAddress());
};
} else if (field_name.find_first_of("UPSTREAM_METADATA") == 0) {
field_extractor_ =
parseUpstreamMetadataField(field_name.substr(STATIC_STRLEN("UPSTREAM_METADATA")));
Expand Down
5 changes: 5 additions & 0 deletions test/common/access_log/access_log_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ TEST(AccessLogFormatterTest, requestInfoFormatter) {
EXPECT_EQ("127.0.0.2:0", upstream_format.format(header, header, request_info));
}

{
RequestInfoFormatter upstream_format("DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT");
EXPECT_EQ("127.0.0.2", upstream_format.format(header, header, request_info));
}

{
RequestInfoFormatter upstream_format("DOWNSTREAM_ADDRESS");
EXPECT_EQ("127.0.0.1", upstream_format.format(header, header, request_info));
Expand Down
10 changes: 10 additions & 0 deletions test/common/router/header_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamRemoteAddressVari
testFormatting("DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT", "127.0.0.1");
}

TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamLocalAddressVariable) {
testFormatting("DOWNSTREAM_LOCAL_ADDRESS", "127.0.0.2:0");
}

TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamLocalAddressWithoutPortVariable) {
testFormatting("DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT", "127.0.0.2");
}

TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithProtocolVariable) {
NiceMock<Envoy::RequestInfo::MockRequestInfo> request_info;
Optional<Envoy::Http::Protocol> protocol = Envoy::Http::Protocol::Http11;
Expand Down Expand Up @@ -252,6 +260,8 @@ TEST(HeaderParserTest, TestParseInternal) {
{"%PROTOCOL%%%", {"HTTP/1.1%"}, {}},
{"%%%PROTOCOL%%%", {"%HTTP/1.1%"}, {}},
{"%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%", {"127.0.0.1"}, {}},
{"%DOWNSTREAM_LOCAL_ADDRESS%", {"127.0.0.2:0"}, {}},
{"%DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT%", {"127.0.0.2"}, {}},
{"%UPSTREAM_METADATA([\"ns\", \"key\"])%", {"value"}, {}},
{"[%UPSTREAM_METADATA([\"ns\", \"key\"])%", {"[value"}, {}},
{"%UPSTREAM_METADATA([\"ns\", \"key\"])%]", {"value]"}, {}},
Expand Down