-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Extend StatefulHeaderFormatter to allow forwarding HTTP1 reason phrase #18997
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ namespace HeaderFormatters { | |
| namespace PreserveCase { | ||
|
|
||
| TEST(PreserveCaseFormatterTest, All) { | ||
| PreserveCaseHeaderFormatter formatter; | ||
| PreserveCaseHeaderFormatter formatter(false); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you verify that when this is false, and you set a reason phrase, you don't get a reason phrase back?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added another test case for this. |
||
| formatter.processKey("Foo"); | ||
| formatter.processKey("Bar"); | ||
| formatter.processKey("BAR"); | ||
|
|
@@ -22,6 +22,22 @@ TEST(PreserveCaseFormatterTest, All) { | |
| EXPECT_EQ("baz", formatter.format("baz")); | ||
| } | ||
|
|
||
| TEST(PreserveCaseFormatterTest, ReasonPhraseEnabled) { | ||
| PreserveCaseHeaderFormatter formatter(true); | ||
|
|
||
| formatter.setReasonPhrase(absl::string_view("Slow Down")); | ||
|
|
||
| EXPECT_EQ("Slow Down", formatter.getReasonPhrase()); | ||
| } | ||
|
|
||
| TEST(PreserveCaseFormatterTest, ReasonPhraseDisabled) { | ||
| PreserveCaseHeaderFormatter formatter(false); | ||
|
|
||
| formatter.setReasonPhrase(absl::string_view("Slow Down")); | ||
|
|
||
| EXPECT_TRUE(formatter.getReasonPhrase().empty()); | ||
| } | ||
|
|
||
| } // namespace PreserveCase | ||
| } // namespace HeaderFormatters | ||
| } // namespace Http | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a release note for this please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.