Skip to content

Commit

Permalink
Add FilterDependencies to base http filter factory interface
Browse files Browse the repository at this point in the history
Signed-off-by: Auni Ahsan <[email protected]>
  • Loading branch information
auni53 committed Feb 23, 2021
1 parent 114d5ae commit 51513a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/envoy/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
10 changes: 10 additions & 0 deletions include/envoy/server/filter_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/server/filter_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ""; };
};
Expand All @@ -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

0 comments on commit 51513a7

Please sign in to comment.