Skip to content

Commit

Permalink
apply suggested changes
Browse files Browse the repository at this point in the history
Signed-off-by: IssaAbuKalbein <isaqalbein@gmail.com>
  • Loading branch information
IssaAbuKalbein committed Mar 5, 2024
1 parent c916d8c commit 6f7f4e2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
1 change: 0 additions & 1 deletion envoy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ envoy_cc_library(
"//envoy/stream_info:filter_state_interface",
"//source/common/common:assert_lib",
"//source/common/common:hash_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand Down
28 changes: 8 additions & 20 deletions envoy/http/header_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "envoy/common/optref.h"
#include "envoy/common/pure.h"
#include "envoy/common/union_string.h"
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/http/header_formatter.h"
#include "envoy/stream_info/filter_state.h"

Expand Down Expand Up @@ -783,6 +782,14 @@ using ResponseTrailerMapConstSharedPtr = std::shared_ptr<const ResponseTrailerMa
using ResponseTrailerMapOptRef = OptRef<ResponseTrailerMap>;
using ResponseTrailerMapOptConstRef = OptRef<const ResponseTrailerMap>;

/**
* Base class for both tunnel response headers and trailers.
*/
class TunnelResponseHeadersOrTrailers : public StreamInfo::FilterState::Object {
public:
virtual const HeaderMap& value() const PURE;
};

/**
* Convenient container type for storing Http::LowerCaseString and std::string key/value pairs.
*/
Expand All @@ -803,25 +810,6 @@ class HeaderMatcher {

using HeaderMatcherSharedPtr = std::shared_ptr<HeaderMatcher>;

/**
* Base class for both tunnel response headers and trailers.
*/
class TunnelResponseHeadersOrTrailers : public StreamInfo::FilterState::Object {
public:
ProtobufTypes::MessagePtr serializeAsProto() const override {
auto proto_out = std::make_unique<envoy::config::core::v3::HeaderMap>();
value().iterate([&proto_out](const HeaderEntry& e) -> HeaderMap::Iterate {
auto* new_header = proto_out->add_headers();
new_header->set_key(std::string(e.key().getStringView()));
new_header->set_value(std::string(e.value().getStringView()));
return HeaderMap::Iterate::Continue;
});
return proto_out;
}

virtual const HeaderMap& value() const PURE;
};

} // namespace Http
} // namespace Envoy

Expand Down
1 change: 1 addition & 0 deletions source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ envoy_cc_library(
"//source/common/common:utility_lib",
"//source/common/runtime:runtime_features_lib",
"//source/common/singleton:const_singleton",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand Down
11 changes: 11 additions & 0 deletions source/common/http/header_map_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ size_t HeaderMapImpl::removeInline(HeaderEntryImpl** ptr_to_entry) {
return 1;
}

ProtobufTypes::MessagePtr TunnelResponseHeadersOrTrailersImpl::serializeAsProto() const {
auto proto_out = std::make_unique<envoy::config::core::v3::HeaderMap>();
value().iterate([&proto_out](const HeaderEntry& e) -> HeaderMap::Iterate {
auto* new_header = proto_out->add_headers();
new_header->set_key(std::string(e.key().getStringView()));
new_header->set_value(std::string(e.value().getStringView()));
return HeaderMap::Iterate::Continue;
});
return proto_out;
}

namespace {
template <class T>
HeaderMapImplUtility::HeaderMapImplInfo makeHeaderMapImplInfo(absl::string_view name) {
Expand Down
6 changes: 6 additions & 0 deletions source/common/http/header_map_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <type_traits>

#include "envoy/common/optref.h"
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/http/header_map.h"

#include "source/common/common/non_copyable.h"
Expand Down Expand Up @@ -636,6 +637,11 @@ class ResponseTrailerMapImpl final : public TypedHeaderMapImpl<ResponseTrailerMa
HeaderEntryImpl* inline_headers_[];
};

class TunnelResponseHeadersOrTrailersImpl : public TunnelResponseHeadersOrTrailers {
public:
ProtobufTypes::MessagePtr serializeAsProto() const override;
};

template <class T>
std::unique_ptr<T>
createHeaderMap(const std::initializer_list<std::pair<LowerCaseString, std::string>>& values) {
Expand Down
4 changes: 2 additions & 2 deletions source/common/tcp_proxy/tcp_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ using TunnelingConfig =
/**
* Response headers for the tunneling connections.
*/
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailersImpl {
public:
TunnelResponseHeaders(Http::ResponseHeaderMapPtr&& response_headers)
: response_headers_(std::move(response_headers)) {}
Expand All @@ -133,7 +133,7 @@ class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
/**
* Response trailers for the tunneling connections.
*/
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailers {
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailersImpl {
public:
TunnelResponseTrailers(Http::ResponseTrailerMapPtr&& response_trailers)
: response_trailers_(std::move(response_trailers)) {}
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/udp/udp_proxy/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using TunnelingConfig =
/**
* Response headers for the tunneling connections.
*/
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailersImpl {
public:
TunnelResponseHeaders(Http::ResponseHeaderMapPtr&& response_headers)
: response_headers_(std::move(response_headers)) {}
Expand All @@ -31,7 +31,7 @@ class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
/**
* Response trailers for the tunneling connections.
*/
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailers {
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailersImpl {
public:
TunnelResponseTrailers(Http::ResponseTrailerMapPtr&& response_trailers)
: response_trailers_(std::move(response_trailers)) {}
Expand Down

0 comments on commit 6f7f4e2

Please sign in to comment.