-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend StatefulHeaderFormatter to allow forwarding HTTP1 reason phrase (
#18997) Signed-off-by: Max Kuznetsov <[email protected]>
- Loading branch information
Showing
12 changed files
with
210 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...header_formatters/preserve_case/preserve_case_formatter_reason_phrase_integration_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "envoy/extensions/http/header_formatters/preserve_case/v3/preserve_case.pb.h" | ||
|
||
#include "test/integration/filters/common.h" | ||
#include "test/integration/http_integration.h" | ||
#include "test/test_common/registry.h" | ||
|
||
namespace Envoy { | ||
namespace { | ||
|
||
struct TestParams { | ||
Network::Address::IpVersion ip_version; | ||
bool forward_reason_phrase; | ||
}; | ||
|
||
std::string testParamsToString(const ::testing::TestParamInfo<TestParams>& p) { | ||
return fmt::format("{}_{}", | ||
p.param.ip_version == Network::Address::IpVersion::v4 ? "IPv4" : "IPv6", | ||
p.param.forward_reason_phrase ? "enabled" : "disabled"); | ||
} | ||
|
||
std::vector<TestParams> getTestsParams() { | ||
std::vector<TestParams> ret; | ||
|
||
for (auto ip_version : TestEnvironment::getIpVersionsForTest()) { | ||
ret.push_back(TestParams{ip_version, true}); | ||
ret.push_back(TestParams{ip_version, false}); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
class PreserveCaseFormatterReasonPhraseIntegrationTest : public testing::TestWithParam<TestParams>, | ||
public HttpIntegrationTest { | ||
public: | ||
PreserveCaseFormatterReasonPhraseIntegrationTest() | ||
: HttpIntegrationTest(Http::CodecType::HTTP1, GetParam().ip_version) {} | ||
|
||
void SetUp() override { | ||
setDownstreamProtocol(Http::CodecType::HTTP1); | ||
setUpstreamProtocol(Http::CodecType::HTTP1); | ||
} | ||
|
||
void initialize() override { | ||
if (upstreamProtocol() == Http::CodecType::HTTP1) { | ||
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) { | ||
ConfigHelper::HttpProtocolOptions protocol_options; | ||
auto typed_extension_config = protocol_options.mutable_explicit_http_config() | ||
->mutable_http_protocol_options() | ||
->mutable_header_key_format() | ||
->mutable_stateful_formatter(); | ||
typed_extension_config->set_name("preserve_case"); | ||
|
||
auto config = | ||
TestUtility::parseYaml<envoy::extensions::http::header_formatters::preserve_case::v3:: | ||
PreserveCaseFormatterConfig>(fmt::format( | ||
"forward_reason_phrase: {}", GetParam().forward_reason_phrase ? "true" : "false")); | ||
typed_extension_config->mutable_typed_config()->PackFrom(config); | ||
|
||
ConfigHelper::setProtocolOptions(*bootstrap.mutable_static_resources()->mutable_clusters(0), | ||
protocol_options); | ||
}); | ||
} | ||
|
||
HttpIntegrationTest::initialize(); | ||
} | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P(CaseFormatter, PreserveCaseFormatterReasonPhraseIntegrationTest, | ||
testing::ValuesIn(getTestsParams()), testParamsToString); | ||
|
||
TEST_P(PreserveCaseFormatterReasonPhraseIntegrationTest, VerifyReasonPhraseEnabled) { | ||
initialize(); | ||
|
||
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("http")); | ||
auto request = "GET / HTTP/1.1\r\nhost: host\r\n\r\n"; | ||
ASSERT_TRUE(tcp_client->write(request, false)); | ||
|
||
Envoy::FakeRawConnectionPtr upstream_connection; | ||
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(upstream_connection)); | ||
|
||
auto response = "HTTP/1.1 503 Slow Down\r\ncontent-length: 0\r\n\r\n"; | ||
ASSERT_TRUE(upstream_connection->write(response)); | ||
|
||
auto expected_reason_phrase = | ||
GetParam().forward_reason_phrase ? "Slow Down" : "Service Unavailable"; | ||
// Verify that the downstream response has proper reason phrase | ||
tcp_client->waitForData(fmt::format("HTTP/1.1 503 {}", expected_reason_phrase), false); | ||
|
||
tcp_client->close(); | ||
} | ||
|
||
} // namespace | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters