Skip to content

Commit

Permalink
addressing final nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriram Rajagopalan committed Feb 27, 2017
1 parent bc79df3 commit 534898e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/intro/arch_overview/http_routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ request. The router filter supports the following features:
* :ref:`Path <config_http_conn_man_route_table_route_path_redirect>`/:ref:`host
<config_http_conn_man_route_table_route_host_redirect>` redirection at the route level.
* :ref:`Explicit host rewriting <config_http_conn_man_route_table_route_host_rewrite>`.
* :ref:`Automatic host rewriting <config_http_conn_man_route_table_route_auto_host_rewrite>` based on DNS name of
the selected upstream host.
* :ref:`Automatic host rewriting <config_http_conn_man_route_table_route_auto_host_rewrite>` based on
the DNS name of the selected upstream host.
* :ref:`Prefix rewriting <config_http_conn_man_route_table_route_prefix_rewrite>`.
* :ref:`Request retries <arch_overview_http_routing_retry>` specified either via HTTP header or via
route configuration.
Expand Down
10 changes: 9 additions & 1 deletion test/common/router/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ TEST_F(RouterTest, AutoHostRewriteEnabled) {
HttpTestUtility::addDefaultHeaders(outgoing_headers);
outgoing_headers.Host()->value(dns_host);

ON_CALL(*cm_.conn_pool_.host_, hostname()).WillByDefault(ReturnRef(dns_host));

EXPECT_CALL(callbacks_.route_->route_entry_, timeout())
.WillOnce(Return(std::chrono::milliseconds(0)));

Expand All @@ -974,6 +976,8 @@ TEST_F(RouterTest, AutoHostRewriteEnabled) {
return nullptr;
}));

// :authority header in the outgoing request should match the DNS name of
// the selected upstream host
EXPECT_CALL(encoder, encodeHeaders(HeaderMapEqualRef(&outgoing_headers), true))
.WillOnce(Invoke([&](const Http::HeaderMap&, bool) -> void {
encoder.stream_.resetStream(Http::StreamResetReason::RemoteReset);
Expand All @@ -983,18 +987,20 @@ TEST_F(RouterTest, AutoHostRewriteEnabled) {
.WillOnce(Invoke([&](const Upstream::HostDescriptionPtr host)
-> void { EXPECT_EQ(host_address_, host->address()); }));
EXPECT_CALL(callbacks_.route_->route_entry_, autoHostRewrite()).WillOnce(Return(true));
EXPECT_CALL(*cm_.conn_pool_.host_, hostname()).WillRepeatedly(ReturnRef(dns_host));
router_.decodeHeaders(incoming_headers, true);
}

TEST_F(RouterTest, AutoHostRewriteDisabled) {
NiceMock<Http::MockStreamEncoder> encoder;
std::string dns_host{"scooby.doo"};
std::string req_host{"foo.bar.com"};

Http::TestHeaderMapImpl incoming_headers;
HttpTestUtility::addDefaultHeaders(incoming_headers);
incoming_headers.Host()->value(req_host);

ON_CALL(*cm_.conn_pool_.host_, hostname()).WillByDefault(ReturnRef(dns_host));

EXPECT_CALL(callbacks_.route_->route_entry_, timeout())
.WillOnce(Return(std::chrono::milliseconds(0)));

Expand All @@ -1005,6 +1011,8 @@ TEST_F(RouterTest, AutoHostRewriteDisabled) {
return nullptr;
}));

// :authority header in the outgoing request should match the :authority header of
// the incoming request
EXPECT_CALL(encoder, encodeHeaders(HeaderMapEqualRef(&incoming_headers), true))
.WillOnce(Invoke([&](const Http::HeaderMap&, bool) -> void {
encoder.stream_.resetStream(Http::StreamResetReason::RemoteReset);
Expand Down
1 change: 1 addition & 0 deletions test/mocks/upstream/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MockHostDescription : public HostDescription {
MOCK_CONST_METHOD0(stats, HostStats&());
MOCK_CONST_METHOD0(zone, const std::string&());

std::string hostname_{};
Network::Address::InstancePtr address_;
testing::NiceMock<Outlier::MockDetectorHostSink> outlier_detector_;
testing::NiceMock<MockClusterInfo> cluster_;
Expand Down

0 comments on commit 534898e

Please sign in to comment.