Skip to content

Commit

Permalink
using using
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Aug 28, 2019
1 parent f41fc17 commit 19f1805
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 39 deletions.
8 changes: 5 additions & 3 deletions source/common/http/conn_manager_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "envoy/config/config_provider.h"
#include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.pb.h"
#include "envoy/http/filter.h"
#include "envoy/router/rds.h"
#include "envoy/stats/scope.h"
Expand Down Expand Up @@ -170,7 +171,8 @@ class DefaultInternalAddressConfig : public Http::InternalAddressConfig {
*/
class ConnectionManagerConfig {
public:
enum class HeaderTransformation { OVERWRITE, APPEND_IF_ABSENT, PASS_THROUGH };
using HttpConnectionManagerProto =
envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager;

virtual ~ConnectionManagerConfig() = default;

Expand Down Expand Up @@ -268,9 +270,9 @@ class ConnectionManagerConfig {
virtual const std::string& serverName() PURE;

/**
* @return HeaderTransformation the transformation to apply to Server response headers.
* @return ServerHeaderTransformation the transformation to apply to Server response headers.
*/
virtual HeaderTransformation serverHeaderTransformation() PURE;
virtual HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() PURE;

/**
* @return ConnectionManagerStats& the stats to write to.
Expand Down
4 changes: 2 additions & 2 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ void ConnectionManagerImpl::ActiveStream::encodeHeaders(ActiveStreamEncoderFilte
connection_manager_.config_.dateProvider().setDateHeader(headers);
// Following setReference() is safe because serverName() is constant for the life of the listener.
const auto transformation = connection_manager_.config_.serverHeaderTransformation();
if (transformation == ConnectionManagerConfig::HeaderTransformation::OVERWRITE ||
(transformation == ConnectionManagerConfig::HeaderTransformation::APPEND_IF_ABSENT &&
if (transformation == ConnectionManagerConfig::HttpConnectionManagerProto::OVERWRITE ||
(transformation == ConnectionManagerConfig::HttpConnectionManagerProto::APPEND_IF_ABSENT &&
headers.Server() == nullptr)) {
headers.insertServer().value().setReference(connection_manager_.config_.serverName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ envoy_cc_library(
"//source/common/router:scoped_rds_lib",
"//source/extensions/filters/network:well_known_names",
"//source/extensions/filters/network/common:factory_base_lib",
"@envoy_api//envoy/config/filter/network/http_connection_manager/v2:http_connection_manager_cc",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,7 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(
access_logs_.push_back(current_access_log);
}

switch (config.server_header_transformation()) {
case envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager::
OVERWRITE:
server_transformation_ = HeaderTransformation::OVERWRITE;
break;
case envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager::
APPEND_IF_ABSENT:
server_transformation_ = HeaderTransformation::APPEND_IF_ABSENT;
break;
case envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager::
PASS_THROUGH:
server_transformation_ = HeaderTransformation::PASS_THROUGH;
break;
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
server_transformation_ = config.server_header_transformation();

if (!config.server_name().empty()) {
server_name_ = config.server_name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
return scoped_routes_config_provider_.get();
}
const std::string& serverName() override { return server_name_; }
HeaderTransformation serverHeaderTransformation() override { return server_transformation_; }
HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() override {
return server_transformation_;
}
Http::ConnectionManagerStats& stats() override { return stats_; }
Http::ConnectionManagerTracingStats& tracingStats() override { return tracing_stats_; }
bool useRemoteAddress() override { return use_remote_address_; }
Expand Down Expand Up @@ -167,7 +169,8 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
CodecType codec_type_;
const Http::Http2Settings http2_settings_;
const Http::Http1Settings http1_settings_;
HeaderTransformation server_transformation_{HeaderTransformation::OVERWRITE};
HttpConnectionManagerProto::ServerHeaderTransformation server_transformation_{
HttpConnectionManagerProto::OVERWRITE};
std::string server_name_;
Http::TracingConnectionManagerConfigPtr tracing_config_;
absl::optional<std::string> user_agent_;
Expand Down
4 changes: 2 additions & 2 deletions source/server/http/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class AdminImpl : public Admin,
return &scoped_route_config_provider_;
}
const std::string& serverName() override { return Http::DefaultServerString::get(); }
HeaderTransformation serverHeaderTransformation() override {
return HeaderTransformation::OVERWRITE;
HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() override {
return HttpConnectionManagerProto::OVERWRITE;
}
Http::ConnectionManagerStats& stats() override { return stats_; }
Http::ConnectionManagerTracingStats& tracingStats() override { return tracing_stats_; }
Expand Down
7 changes: 5 additions & 2 deletions test/common/http/conn_manager_impl_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class FuzzConfig : public ConnectionManagerConfig {
return &scoped_route_config_provider_;
}
const std::string& serverName() override { return server_name_; }
HeaderTransformation serverHeaderTransformation() override { return server_transformation_; }
HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() override {
return server_transformation_;
}
ConnectionManagerStats& stats() override { return stats_; }
ConnectionManagerTracingStats& tracingStats() override { return tracing_stats_; }
bool useRemoteAddress() override { return use_remote_address_; }
Expand Down Expand Up @@ -125,7 +127,8 @@ class FuzzConfig : public ConnectionManagerConfig {
ConnectionManagerImplHelper::RouteConfigProvider route_config_provider_;
ConnectionManagerImplHelper::ScopedRouteConfigProvider scoped_route_config_provider_;
std::string server_name_;
HeaderTransformation server_transformation_{HeaderTransformation::OVERWRITE};
HttpConnectionManagerProto::ServerHeaderTransformation server_transformation_{
HttpConnectionManagerProto::OVERWRITE};
Stats::IsolatedStoreImpl fake_stats_;
ConnectionManagerStats stats_;
ConnectionManagerTracingStats tracing_stats_;
Expand Down
15 changes: 9 additions & 6 deletions test/common/http/conn_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class HttpConnectionManagerImplTest : public testing::Test, public ConnectionMan
return &scoped_route_config_provider_;
}
const std::string& serverName() override { return server_name_; }
HeaderTransformation serverHeaderTransformation() override { return server_transformation_; }
HttpConnectionManagerProto::ServerHeaderTransformation serverHeaderTransformation() override {
return server_transformation_;
}
ConnectionManagerStats& stats() override { return stats_; }
ConnectionManagerTracingStats& tracingStats() override { return tracing_stats_; }
bool useRemoteAddress() override { return use_remote_address_; }
Expand Down Expand Up @@ -317,7 +319,8 @@ class HttpConnectionManagerImplTest : public testing::Test, public ConnectionMan
NiceMock<Network::MockDrainDecision> drain_close_;
std::unique_ptr<ConnectionManagerImpl> conn_manager_;
std::string server_name_;
HeaderTransformation server_transformation_{HeaderTransformation::OVERWRITE};
HttpConnectionManagerProto::ServerHeaderTransformation server_transformation_{
HttpConnectionManagerProto::OVERWRITE};
Network::Address::Ipv4Instance local_address_{"127.0.0.1"};
bool use_remote_address_{true};
Http::DefaultInternalAddressConfig internal_address_config_;
Expand Down Expand Up @@ -567,7 +570,7 @@ TEST_F(HttpConnectionManagerImplTest, ServerHeaderOverwritten) {

// When configured APPEND_IF_ABSENT if the server header is present it will be retained.
TEST_F(HttpConnectionManagerImplTest, ServerHeaderAppendPresent) {
server_transformation_ = HeaderTransformation::APPEND_IF_ABSENT;
server_transformation_ = HttpConnectionManagerProto::APPEND_IF_ABSENT;
setup(false, "custom-value", false);
setUpEncoderAndDecoder(false, false);

Expand All @@ -579,7 +582,7 @@ TEST_F(HttpConnectionManagerImplTest, ServerHeaderAppendPresent) {

// When configured APPEND_IF_ABSENT if the server header is absent the server name will be set.
TEST_F(HttpConnectionManagerImplTest, ServerHeaderAppendAbsent) {
server_transformation_ = HeaderTransformation::APPEND_IF_ABSENT;
server_transformation_ = HttpConnectionManagerProto::APPEND_IF_ABSENT;
setup(false, "custom-value", false);
setUpEncoderAndDecoder(false, false);

Expand All @@ -591,7 +594,7 @@ TEST_F(HttpConnectionManagerImplTest, ServerHeaderAppendAbsent) {

// When configured PASS_THROUGH, the server name will pass through.
TEST_F(HttpConnectionManagerImplTest, ServerHeaderPassthroughPresent) {
server_transformation_ = HeaderTransformation::PASS_THROUGH;
server_transformation_ = HttpConnectionManagerProto::PASS_THROUGH;
setup(false, "custom-value", false);
setUpEncoderAndDecoder(false, false);

Expand All @@ -603,7 +606,7 @@ TEST_F(HttpConnectionManagerImplTest, ServerHeaderPassthroughPresent) {

// When configured PASS_THROUGH, the server header will not be added if absent.
TEST_F(HttpConnectionManagerImplTest, ServerHeaderPassthroughAbsent) {
server_transformation_ = HeaderTransformation::PASS_THROUGH;
server_transformation_ = HttpConnectionManagerProto::PASS_THROUGH;
setup(false, "custom-value", false);
setUpEncoderAndDecoder(false, false);

Expand Down
3 changes: 2 additions & 1 deletion test/common/http/conn_manager_utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class MockConnectionManagerConfig : public ConnectionManagerConfig {
MOCK_METHOD0(routeConfigProvider, Router::RouteConfigProvider*());
MOCK_METHOD0(scopedRouteConfigProvider, Config::ConfigProvider*());
MOCK_METHOD0(serverName, const std::string&());
MOCK_METHOD0(serverHeaderTransformation, HeaderTransformation());
MOCK_METHOD0(serverHeaderTransformation,
HttpConnectionManagerProto::ServerHeaderTransformation());
MOCK_METHOD0(stats, ConnectionManagerStats&());
MOCK_METHOD0(tracingStats, ConnectionManagerTracingStats&());
MOCK_METHOD0(useRemoteAddress, bool());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ stat_prefix: router
ContainerEq(config.tracingConfig()->request_headers_for_tags_));
EXPECT_EQ(*context_.local_info_.address_, config.localAddress());
EXPECT_EQ("foo", config.serverName());
EXPECT_EQ(HttpConnectionManagerConfig::HeaderTransformation::OVERWRITE,
EXPECT_EQ(HttpConnectionManagerConfig::HttpConnectionManagerProto::OVERWRITE,
config.serverHeaderTransformation());
EXPECT_EQ(5 * 60 * 1000, config.streamIdleTimeout().count());
}
Expand Down Expand Up @@ -406,7 +406,7 @@ TEST_F(HttpConnectionManagerConfigTest, ServerOverwrite) {
HttpConnectionManagerConfig config(parseHttpConnectionManagerFromV2Yaml(yaml_string), context_,
date_provider_, route_config_provider_manager_,
scoped_routes_config_provider_manager_);
EXPECT_EQ(HttpConnectionManagerConfig::HeaderTransformation::OVERWRITE,
EXPECT_EQ(HttpConnectionManagerConfig::HttpConnectionManagerProto::OVERWRITE,
config.serverHeaderTransformation());
}

Expand All @@ -426,7 +426,7 @@ TEST_F(HttpConnectionManagerConfigTest, ServerAppendIfAbsent) {
HttpConnectionManagerConfig config(parseHttpConnectionManagerFromV2Yaml(yaml_string), context_,
date_provider_, route_config_provider_manager_,
scoped_routes_config_provider_manager_);
EXPECT_EQ(HttpConnectionManagerConfig::HeaderTransformation::APPEND_IF_ABSENT,
EXPECT_EQ(HttpConnectionManagerConfig::HttpConnectionManagerProto::APPEND_IF_ABSENT,
config.serverHeaderTransformation());
}

Expand All @@ -446,7 +446,7 @@ TEST_F(HttpConnectionManagerConfigTest, ServerPassThrough) {
HttpConnectionManagerConfig config(parseHttpConnectionManagerFromV2Yaml(yaml_string), context_,
date_provider_, route_config_provider_manager_,
scoped_routes_config_provider_manager_);
EXPECT_EQ(HttpConnectionManagerConfig::HeaderTransformation::PASS_THROUGH,
EXPECT_EQ(HttpConnectionManagerConfig::HttpConnectionManagerProto::PASS_THROUGH,
config.serverHeaderTransformation());
}

Expand Down
2 changes: 1 addition & 1 deletion test/server/http/admin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST_P(AdminFilterTest, MiscFunctions) {
EXPECT_EQ(false,
admin_.createUpgradeFilterChain("", nullptr, mock_filter_chain_factory_callbacks));
EXPECT_TRUE(nullptr != admin_.scopedRouteConfigProvider());
EXPECT_EQ(Http::ConnectionManagerConfig::HeaderTransformation::OVERWRITE,
EXPECT_EQ(Http::ConnectionManagerConfig::HttpConnectionManagerProto::OVERWRITE,
admin_.serverHeaderTransformation());
}

Expand Down

0 comments on commit 19f1805

Please sign in to comment.