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

Common TunnelResponseHeadersOrTrailers for UDP & TCP tunneling #32619

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions envoy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ envoy_cc_library(
deps = [
":header_formatter_interface",
"//envoy/common:union_string",
"//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
21 changes: 21 additions & 0 deletions envoy/http/header_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#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"

#include "source/common/common/assert.h"
#include "source/common/common/hash.h"
Expand Down Expand Up @@ -801,6 +803,25 @@ 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 {
IssaAbuKalbein marked this conversation as resolved.
Show resolved Hide resolved
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: 0 additions & 1 deletion source/common/tcp_proxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ envoy_cc_library(
"//source/common/upstream:load_balancer_lib",
"//source/extensions/upstreams/tcp/generic:config",
"@envoy_api//envoy/config/accesslog/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/filters/network/tcp_proxy/v3:pkg_cc_proto",
],
)
12 changes: 0 additions & 12 deletions source/common/tcp_proxy/tcp_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "envoy/buffer/buffer.h"
#include "envoy/config/accesslog/v3/accesslog.pb.h"
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/event/dispatcher.h"
#include "envoy/event/timer.h"
#include "envoy/extensions/filters/network/tcp_proxy/v3/tcp_proxy.pb.h"
Expand Down Expand Up @@ -632,17 +631,6 @@ const Router::MetadataMatchCriteria* Filter::metadataMatchCriteria() {
}
}

ProtobufTypes::MessagePtr TunnelResponseHeadersOrTrailers::serializeAsProto() const {
auto proto_out = std::make_unique<envoy::config::core::v3::HeaderMap>();
value().iterate([&proto_out](const Http::HeaderEntry& e) -> Http::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 Http::HeaderMap::Iterate::Continue;
});
return proto_out;
}

const std::string& TunnelResponseHeaders::key() {
CONSTRUCT_ON_FIRST_USE(std::string, "envoy.tcp_proxy.propagate_response_headers");
}
Expand Down
13 changes: 2 additions & 11 deletions source/common/tcp_proxy/tcp_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,10 @@ using RouteConstSharedPtr = std::shared_ptr<const Route>;
using TunnelingConfig =
envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy_TunnelingConfig;

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

/**
* Response headers for the tunneling connections.
*/
class TunnelResponseHeaders : public TunnelResponseHeadersOrTrailers {
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
public:
TunnelResponseHeaders(Http::ResponseHeaderMapPtr&& response_headers)
: response_headers_(std::move(response_headers)) {}
Expand All @@ -142,7 +133,7 @@ class TunnelResponseHeaders : public TunnelResponseHeadersOrTrailers {
/**
* Response trailers for the tunneling connections.
*/
class TunnelResponseTrailers : public TunnelResponseHeadersOrTrailers {
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailers {
public:
TunnelResponseTrailers(Http::ResponseTrailerMapPtr&& response_trailers)
: response_trailers_(std::move(response_trailers)) {}
Expand Down
11 changes: 0 additions & 11 deletions source/extensions/filters/udp/udp_proxy/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ constexpr uint32_t DefaultMaxConnectAttempts = 1;
constexpr uint32_t DefaultMaxBufferedDatagrams = 1024;
constexpr uint64_t DefaultMaxBufferedBytes = 16384;

ProtobufTypes::MessagePtr TunnelResponseHeadersOrTrailers::serializeAsProto() const {
auto proto_out = std::make_unique<envoy::config::core::v3::HeaderMap>();
value().iterate([&proto_out](const Http::HeaderEntry& e) -> Http::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 Http::HeaderMap::Iterate::Continue;
});
return proto_out;
}

const std::string& TunnelResponseHeaders::key() {
CONSTRUCT_ON_FIRST_USE(std::string, "envoy.udp_proxy.propagate_response_headers");
}
Expand Down
13 changes: 2 additions & 11 deletions source/extensions/filters/udp/udp_proxy/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ namespace UdpProxy {
using TunnelingConfig =
envoy::extensions::filters::udp::udp_proxy::v3::UdpProxyConfig::UdpTunnelingConfig;

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

/**
* Response headers for the tunneling connections.
*/
class TunnelResponseHeaders : public TunnelResponseHeadersOrTrailers {
class TunnelResponseHeaders : public Http::TunnelResponseHeadersOrTrailers {
public:
TunnelResponseHeaders(Http::ResponseHeaderMapPtr&& response_headers)
: response_headers_(std::move(response_headers)) {}
Expand All @@ -40,7 +31,7 @@ class TunnelResponseHeaders : public TunnelResponseHeadersOrTrailers {
/**
* Response trailers for the tunneling connections.
*/
class TunnelResponseTrailers : public TunnelResponseHeadersOrTrailers {
class TunnelResponseTrailers : public Http::TunnelResponseHeadersOrTrailers {
public:
TunnelResponseTrailers(Http::ResponseTrailerMapPtr&& response_trailers)
: response_trailers_(std::move(response_trailers)) {}
Expand Down