11use envoy_proxy_dynamic_modules_rust_sdk:: * ;
22
33/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::HttpFilterConfig`] trait.
4- pub struct PassthroughHttpFilterConfig { }
4+ ///
5+ /// The trait corresponds to a Envoy filter chain configuration.
6+ pub struct PassthroughHttpFilterConfig {
7+ _filter_config : String ,
8+ }
9+
10+ impl PassthroughHttpFilterConfig {
11+ /// This is the constructor for the [`PassthroughHttpFilterConfig`].
12+ ///
13+ /// filter_config is the filter config from the Envoy config here:
14+ /// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/dynamic_modules/v3/dynamic_modules.proto#envoy-v3-api-msg-extensions-dynamic-modules-v3-dynamicmoduleconfig
15+ pub fn new ( filter_config : & str ) -> Self {
16+ Self {
17+ _filter_config : filter_config. to_string ( ) ,
18+ }
19+ }
20+ }
521
622impl < EC : EnvoyHttpFilterConfig , EHF : EnvoyHttpFilter > HttpFilterConfig < EC , EHF >
723 for PassthroughHttpFilterConfig
824{
25+ /// This is called for each new HTTP filter.
926 fn new_http_filter ( & self , _envoy : & mut EC ) -> Box < dyn HttpFilter < EHF > > {
1027 Box :: new ( PassthroughHttpFilter { } )
1128 }
@@ -16,4 +33,43 @@ impl<EC: EnvoyHttpFilterConfig, EHF: EnvoyHttpFilter> HttpFilterConfig<EC, EHF>
1633/// This is a passthrough filter that does nothing.
1734pub struct PassthroughHttpFilter { }
1835
36+ /// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::HttpFilter`] trait.
37+ ///
38+ /// Default implementation of all methods is to return `Continue`.
1939impl < EHF : EnvoyHttpFilter > HttpFilter < EHF > for PassthroughHttpFilter { }
40+
41+ #[ cfg( test) ]
42+ mod tests {
43+ use super :: * ;
44+
45+ #[ test]
46+ /// This demonstrates how to write a test without Envoy using a mock provided by the SDK.
47+ fn test_passthrough_http_filter ( ) {
48+ let mut envoy_filter = envoy_proxy_dynamic_modules_rust_sdk:: MockEnvoyHttpFilter :: new ( ) ;
49+ let mut passthrough_filter = PassthroughHttpFilter { } ;
50+ assert_eq ! (
51+ passthrough_filter. on_request_headers( & mut envoy_filter, false ) ,
52+ abi:: envoy_dynamic_module_type_on_http_filter_request_headers_status:: Continue
53+ ) ;
54+ assert_eq ! (
55+ passthrough_filter. on_request_body( & mut envoy_filter, false ) ,
56+ abi:: envoy_dynamic_module_type_on_http_filter_request_body_status:: Continue
57+ ) ;
58+ assert_eq ! (
59+ passthrough_filter. on_request_trailers( & mut envoy_filter) ,
60+ abi:: envoy_dynamic_module_type_on_http_filter_request_trailers_status:: Continue
61+ ) ;
62+ assert_eq ! (
63+ passthrough_filter. on_response_headers( & mut envoy_filter, false ) ,
64+ abi:: envoy_dynamic_module_type_on_http_filter_response_headers_status:: Continue
65+ ) ;
66+ assert_eq ! (
67+ passthrough_filter. on_response_body( & mut envoy_filter, false ) ,
68+ abi:: envoy_dynamic_module_type_on_http_filter_response_body_status:: Continue
69+ ) ;
70+ assert_eq ! (
71+ passthrough_filter. on_response_trailers( & mut envoy_filter) ,
72+ abi:: envoy_dynamic_module_type_on_http_filter_response_trailers_status:: Continue
73+ ) ;
74+ }
75+ }
0 commit comments