diff --git a/contrib/golang/filters/http/source/BUILD b/contrib/golang/filters/http/source/BUILD index d15a13236aa6a..6e5e85d57dcc7 100644 --- a/contrib/golang/filters/http/source/BUILD +++ b/contrib/golang/filters/http/source/BUILD @@ -38,6 +38,7 @@ envoy_cc_library( "//source/common/http:utility_lib", "//source/common/http/http1:codec_lib", "//source/common/protobuf:utility_lib", + "//source/common/router:string_accessor_lib", "//source/extensions/filters/common/expr:cel_state_lib", "//source/extensions/filters/common/expr:evaluator_lib", "@com_google_cel_cpp//eval/public:activation", diff --git a/contrib/golang/filters/http/source/golang_filter.cc b/contrib/golang/filters/http/source/golang_filter.cc index d63525cb76831..486d16da589d5 100644 --- a/contrib/golang/filters/http/source/golang_filter.cc +++ b/contrib/golang/filters/http/source/golang_filter.cc @@ -7,6 +7,7 @@ #include #include "envoy/http/codes.h" +#include "envoy/router/string_accessor.h" #include "source/common/buffer/buffer_impl.h" #include "source/common/common/base64.h" @@ -18,6 +19,7 @@ #include "source/common/grpc/status.h" #include "source/common/http/headers.h" #include "source/common/http/http1/codec_impl.h" +#include "source/common/router/string_accessor_impl.h" #include "source/extensions/filters/common/expr/context.h" #include "eval/public/cel_value.h" @@ -1054,13 +1056,13 @@ CAPIStatus Filter::setStringFilterState(absl::string_view key, absl::string_view if (isThreadSafe()) { streamInfo().filterState()->setData( - key, std::make_shared(value), + key, std::make_shared(value), static_cast(state_type), static_cast(life_span), static_cast(stream_sharing)); } else { auto key_str = std::string(key); - auto filter_state = std::make_shared(value); + auto filter_state = std::make_shared(value); auto weak_ptr = weak_from_this(); getDispatcher().post( [this, weak_ptr, key_str, filter_state, state_type, life_span, stream_sharing] { @@ -1087,9 +1089,9 @@ CAPIStatus Filter::getStringFilterState(absl::string_view key, uint64_t* value_d } if (isThreadSafe()) { - auto go_filter_state = streamInfo().filterState()->getDataReadOnly(key); + auto go_filter_state = streamInfo().filterState()->getDataReadOnly(key); if (go_filter_state) { - req_->strValue = go_filter_state->value(); + req_->strValue = go_filter_state->asString(); *value_data = reinterpret_cast(req_->strValue.data()); *value_len = req_->strValue.length(); } @@ -1099,9 +1101,9 @@ CAPIStatus Filter::getStringFilterState(absl::string_view key, uint64_t* value_d getDispatcher().post([this, weak_ptr, key_str, value_data, value_len] { if (!weak_ptr.expired() && !hasDestroyed()) { auto go_filter_state = - streamInfo().filterState()->getDataReadOnly(key_str); + streamInfo().filterState()->getDataReadOnly(key_str); if (go_filter_state) { - req_->strValue = go_filter_state->value(); + req_->strValue = go_filter_state->asString(); *value_data = reinterpret_cast(req_->strValue.data()); *value_len = req_->strValue.length(); } diff --git a/contrib/golang/filters/http/source/golang_filter.h b/contrib/golang/filters/http/source/golang_filter.h index f9435eee147c7..f3a9a461c7e60 100644 --- a/contrib/golang/filters/http/source/golang_filter.h +++ b/contrib/golang/filters/http/source/golang_filter.h @@ -370,15 +370,6 @@ struct httpConfigInternal : httpConfig { std::weak_ptr weakFilterConfig() { return config_; } }; -class GoStringFilterState : public StreamInfo::FilterState::Object { -public: - GoStringFilterState(absl::string_view value) : value_(value) {} - const std::string& value() const { return value_; } - -private: - const std::string value_; -}; - } // namespace Golang } // namespace HttpFilters } // namespace Extensions diff --git a/contrib/golang/filters/network/source/BUILD b/contrib/golang/filters/network/source/BUILD index 43c1013b81ae0..4f598d3f9df9e 100644 --- a/contrib/golang/filters/network/source/BUILD +++ b/contrib/golang/filters/network/source/BUILD @@ -19,6 +19,7 @@ envoy_cc_library( ":cgo", ":upstream", "//contrib/golang/common/dso:dso_lib", + "//source/common/router:string_accessor_lib", "@envoy_api//contrib/envoy/extensions/filters/network/golang/v3alpha:pkg_cc_proto", ], ) diff --git a/contrib/golang/filters/network/source/golang.cc b/contrib/golang/filters/network/source/golang.cc index a918996273087..43c09309fd2e5 100644 --- a/contrib/golang/filters/network/source/golang.cc +++ b/contrib/golang/filters/network/source/golang.cc @@ -3,8 +3,10 @@ #include #include "envoy/network/connection.h" +#include "envoy/router/string_accessor.h" #include "source/common/common/assert.h" +#include "source/common/router/string_accessor_impl.h" namespace Envoy { namespace Extensions { @@ -123,13 +125,13 @@ CAPIStatus Filter::setFilterState(absl::string_view key, absl::string_view value if (dispatcher_->isThreadSafe()) { read_callbacks_->connection().streamInfo().filterState()->setData( - key, std::make_shared(value), + key, std::make_shared(value), static_cast(state_type), static_cast(life_span), static_cast(stream_sharing)); } else { auto key_str = std::string(key); - auto filter_state = std::make_shared(value); + auto filter_state = std::make_shared(value); auto weak_ptr = weak_from_this(); dispatcher_->post( [this, weak_ptr, key_str, filter_state, state_type, life_span, stream_sharing] { @@ -160,9 +162,9 @@ CAPIStatus Filter::getFilterState(absl::string_view key, GoString* value_str) { auto go_filter_state = read_callbacks_->connection() .streamInfo() .filterState() - ->getDataReadOnly(key); + ->getDataReadOnly(key); if (go_filter_state) { - wrapper_->str_value_ = go_filter_state->value(); + wrapper_->str_value_ = go_filter_state->asString(); value_str->p = wrapper_->str_value_.data(); value_str->n = wrapper_->str_value_.length(); } @@ -174,9 +176,9 @@ CAPIStatus Filter::getFilterState(absl::string_view key, GoString* value_str) { auto go_filter_state = read_callbacks_->connection() .streamInfo() .filterState() - ->getDataReadOnly(key_str); + ->getDataReadOnly(key_str); if (go_filter_state) { - wrapper_->str_value_ = go_filter_state->value(); + wrapper_->str_value_ = go_filter_state->asString(); value_str->p = wrapper_->str_value_.data(); value_str->n = wrapper_->str_value_.length(); } diff --git a/contrib/golang/filters/network/source/golang.h b/contrib/golang/filters/network/source/golang.h index 5096793baeea4..6060a7fa4755a 100644 --- a/contrib/golang/filters/network/source/golang.h +++ b/contrib/golang/filters/network/source/golang.h @@ -117,15 +117,6 @@ struct FilterWrapper { std::string str_value_; }; -class GoStringFilterState : public StreamInfo::FilterState::Object { -public: - GoStringFilterState(absl::string_view value) : value_(value) {} - const std::string& value() const { return value_; } - -private: - const std::string value_; -}; - } // namespace Golang } // namespace NetworkFilters } // namespace Extensions