diff --git a/include/envoy/server/BUILD b/include/envoy/server/BUILD index 8f0d6691103d..6ffc35a3ffe2 100644 --- a/include/envoy/server/BUILD +++ b/include/envoy/server/BUILD @@ -220,6 +220,7 @@ envoy_cc_library( "//source/common/common:assert_lib", "//source/common/common:macros", "//source/common/protobuf", + "@envoy_api//envoy/extensions/filters/common/dependency/v3:pkg_cc_proto", ], ) diff --git a/include/envoy/server/filter_config.h b/include/envoy/server/filter_config.h index 97b2b3fe51b0..201c9516717b 100644 --- a/include/envoy/server/filter_config.h +++ b/include/envoy/server/filter_config.h @@ -8,6 +8,7 @@ #include "envoy/network/filter.h" #include "envoy/server/drain_manager.h" #include "envoy/server/factory_context.h" +#include "envoy/extensions/filters/common/dependency/v3/dependency.pb.h" #include "common/common/assert.h" #include "common/common/macros.h" @@ -201,6 +202,15 @@ class NamedHttpFilterConfigFactory : public ProtocolOptionsFactory { * @return bool true if this filter must be the last filter in a filter chain, false otherwise. */ virtual bool isTerminalFilter() { return false; } + + /** + * @return FilterDependencies specification of dependencies required or + * provided on the decode and encode paths. + */ + virtual envoy::extensions::filters::common::dependency::v3::FilterDependencies dependencies() { + envoy::extensions::filters::common::dependency::v3::FilterDependencies dependency; + return dependency; + } }; } // namespace Configuration diff --git a/test/server/filter_config_test.cc b/test/server/filter_config_test.cc index b8ddc9e063bf..c4ac3ed323c9 100644 --- a/test/server/filter_config_test.cc +++ b/test/server/filter_config_test.cc @@ -10,6 +10,9 @@ namespace Envoy { namespace { +using envoy::extensions::filters::common::dependency::v3::Dependency; +using envoy::extensions::filters::common::dependency::v3::FilterDependencies; + class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilterConfigFactory { public: TestHttpFilterConfigFactory() = default; @@ -25,6 +28,14 @@ class TestHttpFilterConfigFactory : public Server::Configuration::NamedHttpFilte ProtobufTypes::MessagePtr createEmptyConfigProto() override { return nullptr; } ProtobufTypes::MessagePtr createEmptyProtocolOptionsProto() override { return nullptr; } + FilterDependencies dependencies() override { + FilterDependencies dependencies; + Dependency* d = dependencies.add_decode_required(); + d->set_name("foobar"); + d->set_type(Dependency::FILTER_STATE_KEY); + return dependencies; + } + std::string name() const override { return "envoy.test.http_filter"; } std::string configType() override { return ""; }; }; @@ -38,5 +49,16 @@ TEST(NamedHttpFilterConfigFactoryTest, CreateFilterFactory) { factory.createFilterFactoryFromProto(*message, stats_prefix, context); } +TEST(NamedHttpFilterConfigFactoryTest, Dependencies) { + TestHttpFilterConfigFactory factory; + const std::string stats_prefix = "foo"; + Server::Configuration::MockFactoryContext context; + ProtobufTypes::MessagePtr message{new Envoy::ProtobufWkt::Struct()}; + + factory.createFilterFactoryFromProto(*message, stats_prefix, context); + + EXPECT_EQ(factory.dependencies().decode_required().size(), 1); +} + } // namespace } // namespace Envoy