Skip to content

Commit

Permalink
Sets an oghttp2 config option to allow different "host" and ":authori…
Browse files Browse the repository at this point in the history
…ty" values (#29712)


Signed-off-by: Biren Roy <birenroy@google.com>
  • Loading branch information
birenroy authored Sep 20, 2023
1 parent cd25530 commit fd72723
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/common/http/http2/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,7 @@ ConnectionImpl::Http2Options::Http2Options(
og_options_.max_header_list_bytes = max_headers_kb * 1024;
og_options_.max_header_field_size = max_headers_kb * 1024;
og_options_.allow_extended_connect = http2_options.allow_connect();
og_options_.allow_different_host_and_authority = true;

#ifdef ENVOY_ENABLE_UHV
// UHV - disable header validations in oghttp2
Expand Down
2 changes: 2 additions & 0 deletions test/integration/http_protocol_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct HttpProtocolTestParams {
bool use_universal_header_validator;
};

absl::string_view http2ImplementationToString(Http2Impl impl);

// Allows easy testing of Envoy code for HTTP/HTTP2 upstream/downstream.
//
// Usage:
Expand Down
45 changes: 42 additions & 3 deletions test/integration/multiplexed_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1803,22 +1803,27 @@ TEST_P(MultiplexedRingHashIntegrationTest, CookieRoutingWithCookieWithTtlSet) {

struct FrameIntegrationTestParam {
Network::Address::IpVersion ip_version;
Http2Impl http2_implementation;
};

std::string
frameIntegrationTestParamToString(const testing::TestParamInfo<FrameIntegrationTestParam>& params) {
return TestUtility::ipVersionToString(params.param.ip_version);
return absl::StrCat(TestUtility::ipVersionToString(params.param.ip_version), "_",
http2ImplementationToString(params.param.http2_implementation));
}

class Http2FrameIntegrationTest : public testing::TestWithParam<FrameIntegrationTestParam>,
public Http2RawFrameIntegrationTest {
public:
Http2FrameIntegrationTest() : Http2RawFrameIntegrationTest(GetParam().ip_version) {}
Http2FrameIntegrationTest() : Http2RawFrameIntegrationTest(GetParam().ip_version) {
setupHttp2ImplOverrides(GetParam().http2_implementation);
}

static std::vector<FrameIntegrationTestParam> testParams() {
std::vector<FrameIntegrationTestParam> v;
for (auto ip_version : TestEnvironment::getIpVersionsForTest()) {
v.push_back({ip_version});
v.push_back({ip_version, Http2Impl::Nghttp2});
v.push_back({ip_version, Http2Impl::Oghttp2});
}
return v;
}
Expand Down Expand Up @@ -2058,6 +2063,40 @@ TEST_P(Http2FrameIntegrationTest, AccessLogOfWireBytesIfResponseSizeGreaterThanW
tcp_client_->close();
}

TEST_P(Http2FrameIntegrationTest, HostDifferentFromAuthority) {
beginSession();

uint32_t request_idx = 0;
auto request = Http2Frame::makeRequest(Http2Frame::makeClientStreamId(request_idx),
"one.example.com", "/path", {{"host", "two.example.com"}});
sendFrame(request);

waitForNextUpstreamRequest();
EXPECT_EQ(upstream_request_->headers().getHostValue(), "one.example.com,two.example.com");
upstream_request_->encodeHeaders(default_response_headers_, true);
auto frame = readFrame();
EXPECT_EQ(Http2Frame::Type::Headers, frame.type());
EXPECT_EQ(Http2Frame::ResponseStatus::Ok, frame.responseStatus());
tcp_client_->close();
}

TEST_P(Http2FrameIntegrationTest, HostSameAsAuthority) {
beginSession();

uint32_t request_idx = 0;
auto request = Http2Frame::makeRequest(Http2Frame::makeClientStreamId(request_idx),
"one.example.com", "/path", {{"host", "one.example.com"}});
sendFrame(request);

waitForNextUpstreamRequest();
EXPECT_EQ(upstream_request_->headers().getHostValue(), "one.example.com,one.example.com");
upstream_request_->encodeHeaders(default_response_headers_, true);
auto frame = readFrame();
EXPECT_EQ(Http2Frame::Type::Headers, frame.type());
EXPECT_EQ(Http2Frame::ResponseStatus::Ok, frame.responseStatus());
tcp_client_->close();
}

INSTANTIATE_TEST_SUITE_P(IpVersions, Http2FrameIntegrationTest,
testing::ValuesIn(Http2FrameIntegrationTest::testParams()),
frameIntegrationTestParamToString);
Expand Down

0 comments on commit fd72723

Please sign in to comment.