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

Add setRequestDecoder to ResponseEncoder interface #24368

Merged
merged 8 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions envoy/http/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const char MaxResponseHeadersCountOverrideKey[] =
"envoy.reloadable_features.max_response_headers_count";

class Stream;
class RequestDecoder;

/**
* Error codes used to convey the reason for a GOAWAY.
Expand Down Expand Up @@ -165,6 +166,12 @@ class ResponseEncoder : public virtual StreamEncoder {
* error.
*/
virtual bool streamErrorOnInvalidHttpMessage() const PURE;

/**
* Set a new request decoder for this ResponseEncoder.
* @param decoder new request decoder.
Copy link
Contributor

Choose a reason for hiding this comment

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

think it's worth a comment on why this is a useful association?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, ptal!

*/
virtual void setRequestDecoder(RequestDecoder& decoder) PURE;
};

/**
Expand Down
2 changes: 2 additions & 0 deletions source/common/http/http1/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class ResponseEncoderImpl : public StreamEncoderImpl, public ResponseEncoder {
return stream_error_on_invalid_http_message_;
}

void setRequestDecoder(Http::RequestDecoder& /*decoder*/) override {}
Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe why HTTP/1.1 doesn't need this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. H/1 will need more work to actually reset the decoder on internal redirect, but it seems like we don't need to tackle that now?

Copy link
Contributor

Choose a reason for hiding this comment

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

We will need to make it work for H1 to defer logging I guess? Can you add a TODO?


// Http1::StreamEncoderImpl
void resetStream(StreamResetReason reason) override;

Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http2/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ Status ServerConnectionImpl::onBeginHeaders(const nghttp2_frame* frame) {
if (connection_.aboveHighWatermark()) {
stream->runHighWatermarkCallbacks();
}
stream->request_decoder_ = &callbacks_.newStream(*stream);
stream->setRequestDecoder(callbacks_.newStream(*stream));
stream->stream_id_ = frame->hd.stream_id;
LinkedList::moveIntoList(std::move(stream), active_streams_);
adapter_->SetStreamUserData(frame->hd.stream_id, active_streams_.front().get());
Expand Down
5 changes: 4 additions & 1 deletion source/common/http/http2/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,19 @@ class ConnectionImpl : public virtual Connection,
void encodeTrailers(const ResponseTrailerMap& trailers) override {
encodeTrailersBase(trailers);
}
void setRequestDecoder(Http::RequestDecoder& decoder) override { request_decoder_ = &decoder; }

// ScopeTrackedObject
void dumpState(std::ostream& os, int indent_level) const override;

RequestDecoder* request_decoder_{};
absl::variant<RequestHeaderMapPtr, RequestTrailerMapPtr> headers_or_trailers_;

bool streamErrorOnInvalidHttpMessage() const override {
return parent_.stream_error_on_invalid_http_messaging_;
}

private:
RequestDecoder* request_decoder_{};
};

using ServerStreamImplPtr = std::unique_ptr<ServerStreamImpl>;
Expand Down
2 changes: 1 addition & 1 deletion source/common/quic/envoy_quic_server_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EnvoyQuicServerStream : public quic::QuicSpdyServerStreamBase,
envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
headers_with_underscores_action);

void setRequestDecoder(Http::RequestDecoder& decoder) { request_decoder_ = &decoder; }
void setRequestDecoder(Http::RequestDecoder& decoder) override { request_decoder_ = &decoder; }

// Http::StreamEncoder
void encode1xxHeaders(const Http::ResponseHeaderMap& headers) override;
Expand Down
1 change: 1 addition & 0 deletions test/mocks/http/stream_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MockResponseEncoder : public ResponseEncoder {
MOCK_METHOD(void, encode1xxHeaders, (const ResponseHeaderMap& headers));
MOCK_METHOD(void, encodeHeaders, (const ResponseHeaderMap& headers, bool end_stream));
MOCK_METHOD(void, encodeTrailers, (const ResponseTrailerMap& trailers));
MOCK_METHOD(void, setRequestDecoder, (RequestDecoder & decoder));

// Http::StreamEncoder
MOCK_METHOD(void, encodeData, (Buffer::Instance & data, bool end_stream));
Expand Down