Skip to content

Commit 6b89c36

Browse files
authored
http: add server context only factory support to grpc_web filter (#43296)
<!-- !!!ATTENTION!!! If you are fixing *any* crash or *any* potential security issue, *do not* open a pull request in this repo. Please report the issue via emailing envoy-security@googlegroups.com where the issue will be triaged appropriately. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> Commit Message: Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
1 parent 80b486a commit 6b89c36

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

source/extensions/filters/http/grpc_web/config.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Http::FilterFactoryCb GrpcWebFilterConfig::createFilterFactoryFromProtoTyped(
1818
};
1919
}
2020

21+
Http::FilterFactoryCb GrpcWebFilterConfig::createFilterFactoryFromProtoWithServerContextTyped(
22+
const envoy::extensions::filters::http::grpc_web::v3::GrpcWeb&, const std::string&,
23+
Server::Configuration::ServerFactoryContext& factory_context) {
24+
return [&factory_context](Http::FilterChainFactoryCallbacks& callbacks) {
25+
callbacks.addStreamFilter(std::make_shared<GrpcWebFilter>(factory_context.grpcContext()));
26+
};
27+
}
28+
2129
/**
2230
* Static registration for the gRPC-Web filter. @see RegisterFactory.
2331
*/

source/extensions/filters/http/grpc_web/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class GrpcWebFilterConfig
2020
const envoy::extensions::filters::http::grpc_web::v3::GrpcWeb& proto_config,
2121
const std::string& stats_prefix,
2222
Server::Configuration::FactoryContext& factory_context) override;
23+
24+
Http::FilterFactoryCb createFilterFactoryFromProtoWithServerContextTyped(
25+
const envoy::extensions::filters::http::grpc_web::v3::GrpcWeb& proto_config,
26+
const std::string& stats_prefix,
27+
Server::Configuration::ServerFactoryContext& factory_context) override;
2328
};
2429

2530
} // namespace GrpcWeb

test/extensions/filters/http/grpc_web/config_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ TEST(GrpcWebFilterConfigTest, GrpcWebFilter) {
2323
cb(filter_callback);
2424
}
2525

26+
TEST(GrpcWebFilterConfigTest, GrpcWebFilterWithServerContext) {
27+
NiceMock<Server::Configuration::MockServerFactoryContext> context;
28+
GrpcWebFilterConfig factory;
29+
envoy::extensions::filters::http::grpc_web::v3::GrpcWeb config;
30+
Http::FilterFactoryCb cb =
31+
factory.createFilterFactoryFromProtoWithServerContext(config, "stats", context);
32+
Http::MockFilterChainFactoryCallbacks filter_callback;
33+
EXPECT_CALL(filter_callback, addStreamFilter(_));
34+
cb(filter_callback);
35+
}
36+
2637
} // namespace
2738
} // namespace GrpcWeb
2839
} // namespace HttpFilters

0 commit comments

Comments
 (0)