Skip to content
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
6 changes: 6 additions & 0 deletions docs/root/configuration/http/http_conn_man/headers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ Supported variable names are:
The original protocol which is already added by Envoy as a
:ref:`x-forwarded-proto <config_http_conn_man_headers_x-forwarded-proto>` request header.

%REQUESTED_SERVER_NAME%
HTTP
String value set on ssl connection socket for Server Name Indication (SNI)
TCP
String value set on ssl connection socket for Server Name Indication (SNI)

%UPSTREAM_METADATA(["namespace", "key", ...])%
Populates the header with :ref:`EDS endpoint metadata <envoy_v3_api_field_config.endpoint.v3.LbEndpoint.metadata>` from the
upstream host selected by the router. Metadata may be selected from any namespace. In general,
Expand Down
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ New Features
* dns_resolver: added :ref:`CaresDnsResolverConfig<envoy_v3_api_msg_extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig>` to support c-ares DNS resolver as an extension.
* dns_resolver: added :ref:`AppleDnsResolverConfig<envoy_v3_api_msg_extensions.network.dns_resolver.apple.v3.AppleDnsResolverConfig>` to support apple DNS resolver as an extension.
* ext_authz: added :ref:`query_parameters_to_set <envoy_v3_api_field_service.auth.v3.OkHttpResponse.query_parameters_to_set>` and :ref:`query_parameters_to_remove <envoy_v3_api_field_service.auth.v3.OkHttpResponse.query_parameters_to_remove>` for adding and removing query string parameters when using a gRPC authorization server.
* http: added support for %REQUESTED_SERVER_NAME% to extract SNI as a custom header.
* http: added support for :ref:`retriable health check status codes <envoy_v3_api_field_config.core.v3.HealthCheck.HttpHealthCheck.retriable_statuses>`.
* http: added timing information about upstream connection and encryption establishment to stream info. These can currently be accessed via custom access loggers.
* listener: added API for extensions to access :ref:`typed_filter_metadata <envoy_v3_api_field_config.core.v3.Metadata.typed_filter_metadata>` configured in the listener's :ref:`metadata <envoy_v3_api_field_config.listener.v3.Listener.metadata>` field.
Expand Down
4 changes: 4 additions & 0 deletions source/common/router/header_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ StreamInfoHeaderFormatter::StreamInfoHeaderFormatter(absl::string_view field_nam
return Envoy::Formatter::SubstitutionFormatUtils::protocolToStringOrDefault(
stream_info.protocol());
};
} else if (field_name == "REQUESTED_SERVER_NAME") {
field_extractor_ = [](const StreamInfo::StreamInfo& stream_info) -> std::string {
return std::string(stream_info.downstreamAddressProvider().requestedServerName());
};
} else if (field_name == "DOWNSTREAM_REMOTE_ADDRESS") {
field_extractor_ = [](const StreamInfo::StreamInfo& stream_info) {
return stream_info.downstreamAddressProvider().remoteAddress()->asString();
Expand Down
14 changes: 14 additions & 0 deletions test/common/router/header_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ TEST_F(StreamInfoHeaderFormatterTest, TestFormatWithProtocolVariable) {
testFormatting(stream_info, "PROTOCOL", "HTTP/1.1");
}

TEST_F(StreamInfoHeaderFormatterTest, TestFormatWithRequestedServerNameVariable) {
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
// Validate for empty Request Server Name
testFormatting(stream_info, "REQUESTED_SERVER_NAME", "");

// Validate for a valid Request Server Name
const std::string requested_server_name = "foo.bar";
stream_info.downstream_connection_info_provider_->setRequestedServerName(requested_server_name);
testFormatting(stream_info, "REQUESTED_SERVER_NAME", requested_server_name);
}

TEST_F(StreamInfoHeaderFormatterTest, TestFormatWithDownstreamPeerUriSanVariableSingleSan) {
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
auto connection_info = std::make_shared<NiceMock<Ssl::MockConnectionInfo>>();
Expand Down Expand Up @@ -835,6 +846,7 @@ TEST(HeaderParserTest, TestParseInternal) {
{"%UPSTREAM_METADATA( \t [ \t \"ns\" \t , \t \"key\" \t ] \t )%", {"value"}, {}},
{R"EOF(%UPSTREAM_METADATA(["\"quoted\"", "\"key\""])%)EOF", {"value"}, {}},
{"%UPSTREAM_REMOTE_ADDRESS%", {"10.0.0.1:443"}, {}},
{"%REQUESTED_SERVER_NAME%", {"foo.bar"}, {}},
{"%PER_REQUEST_STATE(testing)%", {"test_value"}, {}},
{"%REQ(x-request-id)%", {"123"}, {}},
{"%START_TIME%", {"2018-04-03T23:06:09.123Z"}, {}},
Expand Down Expand Up @@ -932,6 +944,8 @@ TEST(HeaderParserTest, TestParseInternal) {
};

NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;
const std::string requested_server_name = "foo.bar";
stream_info.downstream_connection_info_provider_->setRequestedServerName(requested_server_name);
absl::optional<Envoy::Http::Protocol> protocol = Envoy::Http::Protocol::Http11;
ON_CALL(stream_info, protocol()).WillByDefault(ReturnPointee(&protocol));

Expand Down