Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream: not trying to do HTTP/3 where not configured #17454

Merged
merged 3 commits into from
Jul 29, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ message HttpProtocolOptions {

// If this is used, the cluster can use either of the configured protocols, and
// will use whichever protocol was used by the downstream connection.
//
// If HTTP/3 is configured for downstream and not configured for upstream,
// HTTP/3 requests will fail over to HTTP/2.
message UseDownstreamHttpConfig {
config.core.v3.Http1ProtocolOptions http_protocol_options = 1;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ std::vector<Http::Protocol>
ClusterInfoImpl::upstreamHttpProtocol(absl::optional<Http::Protocol> downstream_protocol) const {
if (downstream_protocol.has_value() &&
features_ & Upstream::ClusterInfo::Features::USE_DOWNSTREAM_PROTOCOL) {
if (downstream_protocol.value() == Http::Protocol::Http3 &&
!(features_ & Upstream::ClusterInfo::Features::HTTP3)) {
return {Http::Protocol::Http2};
}
return {downstream_protocol.value()};
}

Expand Down
57 changes: 55 additions & 2 deletions test/common/upstream/upstream_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3131,7 +3131,7 @@ TEST_F(ClusterInfoImplTest, ExtensionProtocolOptionsForFilterWithOptions) {
}
}

TEST_F(ClusterInfoImplTest, UseDownstreamHttpProtocol) {
TEST_F(ClusterInfoImplTest, UseDownstreamHttpProtocolWithDowngrade) {
const std::string yaml = R"EOF(
name: name
connect_timeout: 0.25s
Expand All @@ -3148,7 +3148,8 @@ TEST_F(ClusterInfoImplTest, UseDownstreamHttpProtocol) {
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http11})[0]);
EXPECT_EQ(Http::Protocol::Http2,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http2})[0]);
EXPECT_EQ(Http::Protocol::Http3,
// This will get downgraded because the cluster does not support HTTP/3
EXPECT_EQ(Http::Protocol::Http2,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http3})[0]);
}

Expand Down Expand Up @@ -3367,6 +3368,58 @@ TEST_F(ClusterInfoImplTest, Http3Auto) {
auto_h3->info()->http3Options().quic_protocol_options().max_concurrent_streams().value(), 2);
}

TEST_F(ClusterInfoImplTest, UseDownstreamHttpProtocolWithoutDowngrade) {
const std::string yaml = TestEnvironment::substitute(R"EOF(
name: name
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: foo.bar.com
port_value: 443
transport_socket:
name: envoy.transport_sockets.quic
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport
upstream_tls_context:
common_tls_context:
tls_certificates:
- certificate_chain:
filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/san_uri_cert.pem"
private_key:
filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/san_uri_key.pem"
validation_context:
trusted_ca:
filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/ca_cert.pem"
match_subject_alt_names:
- exact: localhost
- exact: 127.0.0.1
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
use_downstream_protocol_config:
http3_protocol_options: {}
common_http_protocol_options:
idle_timeout: 1s
)EOF",
Network::Address::IpVersion::v4);
auto cluster = makeCluster(yaml);

EXPECT_EQ(Http::Protocol::Http10,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http10})[0]);
EXPECT_EQ(Http::Protocol::Http11,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http11})[0]);
EXPECT_EQ(Http::Protocol::Http2,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http2})[0]);
EXPECT_EQ(Http::Protocol::Http3,
cluster->info()->upstreamHttpProtocol({Http::Protocol::Http3})[0]);
}

#else
TEST_F(ClusterInfoImplTest, Http3BadConfig) {
const std::string yaml = TestEnvironment::substitute(R"EOF(
Expand Down