Skip to content

Commit

Permalink
Add DOWNSTREAM_LOCAL_ADDRESS header variable
Browse files Browse the repository at this point in the history
Signed-off-by: Mandar U Jog <[email protected]>
  • Loading branch information
mandarjog committed Jan 31, 2018
1 parent 16e7335 commit c68677f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/common/router/header_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ 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(
Expand Down
5 changes: 5 additions & 0 deletions test/common/router/header_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ TEST_F(RequestInfoHeaderFormatterTest, TestFormatWithDownstreamRemoteAddressVari
}

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");
}

Expand Down Expand Up @@ -256,6 +260,7 @@ 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"}, {}},
Expand Down

0 comments on commit c68677f

Please sign in to comment.