forked from envoyproxy/envoy-filter-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_filter_config.cc
55 lines (44 loc) · 1.88 KB
/
http_filter_config.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string>
#include "envoy/registry/registry.h"
#include "envoy/server/filter_config.h"
#include "http-filter-example/http_filter.pb.h"
#include "http-filter-example/http_filter.pb.validate.h"
#include "http_filter.h"
namespace Envoy {
namespace Server {
namespace Configuration {
class HttpSampleDecoderFilterConfigFactory : public NamedHttpFilterConfigFactory {
public:
Http::FilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& proto_config,
const std::string&,
FactoryContext& context) override {
return createFilter(Envoy::MessageUtil::downcastAndValidate<const sample::Decoder&>(
proto_config, context.messageValidationVisitor()),
context);
}
/**
* Return the Protobuf Message that represents your config incase you have config proto
*/
ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return ProtobufTypes::MessagePtr{new sample::Decoder()};
}
std::string name() const override { return "sample"; }
private:
Http::FilterFactoryCb createFilter(const sample::Decoder& proto_config, FactoryContext&) {
Http::HttpSampleDecoderFilterConfigSharedPtr config =
std::make_shared<Http::HttpSampleDecoderFilterConfig>(
Http::HttpSampleDecoderFilterConfig(proto_config));
return [config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
auto filter = new Http::HttpSampleDecoderFilter(config);
callbacks.addStreamDecoderFilter(Http::StreamDecoderFilterSharedPtr{filter});
};
}
};
/**
* Static registration for this sample filter. @see RegisterFactory.
*/
static Registry::RegisterFactory<HttpSampleDecoderFilterConfigFactory, NamedHttpFilterConfigFactory>
register_;
} // namespace Configuration
} // namespace Server
} // namespace Envoy