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

http: adding response code details for downstream HTTP/1.1 codec errors #9286

Merged
merged 4 commits into from
Dec 12, 2019

Conversation

alyssawilk
Copy link
Contributor

@alyssawilk alyssawilk commented Dec 9, 2019

Also adding a fix to Connect header rejection where the codec sent a protocol error without throwing an exception.

Risk Level: Medium (minimal tweaks to data plane code)
Testing: new unit tests, integration test
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Comment on lines 27 to 36
struct Http1ResponseCodeDetailValues {
const std::string TooManyHeaders = "http1.too_many_headers";
const std::string HeadersTooLarge = "http1.headers_too_large";
const std::string HttpCodecError = "http1.codec_error";
const std::string InvalidCharacters = "http1.invalid_characters";
const std::string ConnectionHeaderSanitization = "http1.connection_header_bad";
const std::string InvalidUrl = "http1.invalid_url";
};

using Http1ResponseCodeDetails = ConstSingleton<Http1ResponseCodeDetailValues>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can all be absl::string_view instead. They're always passed to functions expecting string_view.

Also, honestly since there's no initialization order fiasco here involved.
Why not just declare all those literals as constexpr auto var = "..."?
Then you wouldn't need any allocations in the singleton and no std::string allocations either (even though many of the values here qualify for SSO)

@@ -367,6 +367,10 @@ void ConnectionManagerImpl::resetAllStreams(
stream.onResetStream(StreamResetReason::ConnectionTermination, absl::string_view());
if (response_flag.has_value()) {
stream.stream_info_.setResponseFlag(response_flag.value());
if (response_flag.value() == StreamInfo::ResponseFlag::DownstreamProtocolError) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

micro optimization: you already checked that is has_value() above. You can use the value directly *response_flag and save a branch.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nice improvement. LGTM with some small comments.

/wait

@@ -1349,6 +1349,7 @@ TEST_F(Http1ServerConnectionImplTest, LargeRequestHeadersSplitRejected) {
// the 60th 1kb header should induce overflow
buffer = Buffer::OwnedImpl(fmt::format("big: {}\r\n", long_string));
EXPECT_THROW_WITH_MESSAGE(codec_->dispatch(buffer), EnvoyException, "headers size exceeds limit");
EXPECT_EQ("http1.headers_too_large", response_encoder->getStream().responseDetails());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get tests that cover each of the new details?

/*
* @return string_view optionally return the reason behind codec level errors.
*/
virtual absl::string_view responseDetails() { return ""; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning this error this way, WDYT about just throwing this out with the CodecProtocolException? I think this would lead to clearer logic since in the HCM it can just be passed into the code that resets all of the streams?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I started with that, but it didn't work the way I wanted to, because if one H2 stream has bad headers, I only wanted that particular stream to be tagged with bad headers - the others would maybe eventually get flagged with "you shared a connection with a bad stream" but shouldn't be tagged with the error that wasn't theirs. Only the codec knows which stream causes the problem so it has to be on a per-stream basis to be tagged correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that makes sense. Can you leave a comment trail about that thought process?

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo extra comment and format fix.

/wait

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@alyssawilk alyssawilk merged commit 7b834b5 into envoyproxy:master Dec 12, 2019
prakhag1 pushed a commit to prakhag1/envoy that referenced this pull request Jan 3, 2020
…rs (envoyproxy#9286)

Also adding a fix to Connect header rejection where the codec sent a protocol error without throwing an exception.

Risk Level: Medium (minimal tweaks to data plane code)
Testing: new unit tests, integration test
Docs Changes: n/a
Release Notes: n/a
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Prakhar <prakhar_au@yahoo.com>
@alyssawilk alyssawilk deleted the http1_details branch May 18, 2020 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants