Skip to content

Commit

Permalink
Add DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT
Browse files Browse the repository at this point in the history
Add DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT to header_formatter
and access_log_formatter.

Signed-off-by: Mandar U Jog <[email protected]>
  • Loading branch information
mandarjog committed Jan 31, 2018
1 parent 4ac478c commit 16e7335
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
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
3 changes: 1 addition & 2 deletions source/common/router/header_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ RequestInfoHeaderFormatter::RequestInfoHeaderFormatter(absl::string_view field_n
return RequestInfo::Utility::formatDownstreamAddressNoPort(
*request_info.downstreamRemoteAddress());
};
} else if (field_name == "ORIGINAL_DST" ||
field_name == "DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT") {
} else if (field_name == "DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT") {
field_extractor_ = [](const Envoy::RequestInfo::RequestInfo& request_info) {
return RequestInfo::Utility::formatDownstreamAddressNoPort(
*request_info.downstreamLocalAddress());
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
5 changes: 0 additions & 5 deletions test/common/router/header_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamRemoteAddressVari
testFormatting("DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT", "127.0.0.1");
}

TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithOriginalDstVariable) {
testFormatting("ORIGINAL_DST", "127.0.0.2");
}

TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamLocalAddressVariable) {
testFormatting("DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT", "127.0.0.2");
}
Expand Down Expand Up @@ -261,7 +257,6 @@ TEST(HeaderParserTest, TestParseInternal) {
{"%%%PROTOCOL%%%", {"%HTTP/1.1%"}, {}},
{"%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT%", {"127.0.0.1"}, {}},
{"%DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT%", {"127.0.0.2"}, {}},
{"%ORIGINAL_DST%", {"127.0.0.2"}, {}},
{"%UPSTREAM_METADATA([\"ns\", \"key\"])%", {"value"}, {}},
{"[%UPSTREAM_METADATA([\"ns\", \"key\"])%", {"[value"}, {}},
{"%UPSTREAM_METADATA([\"ns\", \"key\"])%]", {"value]"}, {}},
Expand Down

0 comments on commit 16e7335

Please sign in to comment.