diff options
author | Muxi Yan <muxi@users.noreply.github.com> | 2018-04-02 11:02:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 11:02:07 -0700 |
commit | 6a1bf82ea9ac1b1d36a6d0ee48299a978a8fc964 (patch) | |
tree | 5a123524bff30fb1ca1da0544f3500d786189111 /src | |
parent | c958b70219b6d4996d7dc830dbe15eaed6ebde9f (diff) | |
parent | dfbf607ccb2a9871ee6cb2dfc8692dcbc02427b4 (diff) |
Merge pull request #14893 from muxi/runtime-plugin-enable
Use channel arg to disable authority filter
Diffstat (limited to 'src')
6 files changed, 53 insertions, 37 deletions
diff --git a/src/core/ext/filters/http/client_authority_filter.cc b/src/core/ext/filters/http/client_authority_filter.cc index 855007500a..1f57ab5ce6 100644 --- a/src/core/ext/filters/http/client_authority_filter.cc +++ b/src/core/ext/filters/http/client_authority_filter.cc @@ -129,6 +129,17 @@ const grpc_channel_filter grpc_client_authority_filter = { static bool add_client_authority_filter(grpc_channel_stack_builder* builder, void* arg) { + const grpc_channel_args* channel_args = + grpc_channel_stack_builder_get_channel_arguments(builder); + const grpc_arg* disable_client_authority_filter_arg = grpc_channel_args_find( + channel_args, GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER); + if (disable_client_authority_filter_arg != nullptr) { + const bool is_client_authority_filter_disabled = + grpc_channel_arg_get_bool(disable_client_authority_filter_arg, false); + if (is_client_authority_filter_disabled) { + return true; + } + } return grpc_channel_stack_builder_prepend_filter( builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr); } diff --git a/src/core/plugin_registry/grpc_cronet_plugin_registry.cc b/src/core/plugin_registry/grpc_cronet_plugin_registry.cc index 84228cb38a..49b9c7d4fe 100644 --- a/src/core/plugin_registry/grpc_cronet_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_cronet_plugin_registry.cc @@ -20,50 +20,30 @@ #include <grpc/grpc.h> -void grpc_deadline_filter_init(void); -void grpc_deadline_filter_shutdown(void); -void grpc_client_channel_init(void); -void grpc_client_channel_shutdown(void); -void grpc_lb_policy_pick_first_init(void); -void grpc_lb_policy_pick_first_shutdown(void); -void grpc_max_age_filter_init(void); -void grpc_max_age_filter_shutdown(void); -void grpc_message_size_filter_init(void); -void grpc_message_size_filter_shutdown(void); -void grpc_resolver_dns_native_init(void); -void grpc_resolver_dns_native_shutdown(void); -void grpc_resolver_sockaddr_init(void); -void grpc_resolver_sockaddr_shutdown(void); -void grpc_server_load_reporting_plugin_init(void); -void grpc_server_load_reporting_plugin_shutdown(void); void grpc_http_filters_init(void); void grpc_http_filters_shutdown(void); void grpc_chttp2_plugin_init(void); void grpc_chttp2_plugin_shutdown(void); +void grpc_deadline_filter_init(void); +void grpc_deadline_filter_shutdown(void); +void grpc_client_channel_init(void); +void grpc_client_channel_shutdown(void); void grpc_tsi_alts_init(void); void grpc_tsi_alts_shutdown(void); +void grpc_server_load_reporting_plugin_init(void); +void grpc_server_load_reporting_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { - grpc_register_plugin(grpc_deadline_filter_init, - grpc_deadline_filter_shutdown); - grpc_register_plugin(grpc_client_channel_init, - grpc_client_channel_shutdown); - grpc_register_plugin(grpc_lb_policy_pick_first_init, - grpc_lb_policy_pick_first_shutdown); - grpc_register_plugin(grpc_max_age_filter_init, - grpc_max_age_filter_shutdown); - grpc_register_plugin(grpc_message_size_filter_init, - grpc_message_size_filter_shutdown); - grpc_register_plugin(grpc_resolver_dns_native_init, - grpc_resolver_dns_native_shutdown); - grpc_register_plugin(grpc_resolver_sockaddr_init, - grpc_resolver_sockaddr_shutdown); - grpc_register_plugin(grpc_server_load_reporting_plugin_init, - grpc_server_load_reporting_plugin_shutdown); grpc_register_plugin(grpc_http_filters_init, grpc_http_filters_shutdown); grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); + grpc_register_plugin(grpc_deadline_filter_init, + grpc_deadline_filter_shutdown); + grpc_register_plugin(grpc_client_channel_init, + grpc_client_channel_shutdown); grpc_register_plugin(grpc_tsi_alts_init, grpc_tsi_alts_shutdown); + grpc_register_plugin(grpc_server_load_reporting_plugin_init, + grpc_server_load_reporting_plugin_shutdown); } diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index c282fbd194..152c3d3ed6 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -192,7 +192,7 @@ static NSMutableDictionary *kHostCache; return YES; } -- (NSDictionary *)channelArgs { +- (NSDictionary *)channelArgsUsingCronet:(BOOL)useCronet { NSMutableDictionary *args = [NSMutableDictionary dictionary]; // TODO(jcanizales): Add OS and device information (see @@ -226,14 +226,19 @@ static NSMutableDictionary *kHostCache; args[@GRPC_ARG_MOBILE_LOG_CONFIG] = logConfig; } + if (useCronet) { + args[@GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER] = [NSNumber numberWithInt:1]; + } + return args; } - (GRPCChannel *)newChannel { - NSDictionary *args = [self channelArgs]; + BOOL useCronet = NO; #ifdef GRPC_COMPILE_WITH_CRONET - BOOL useCronet = [GRPCCall isUsingCronet]; + useCronet = [GRPCCall isUsingCronet]; #endif + NSDictionary *args = [self channelArgsUsingCronet:useCronet]; if (_secure) { GRPCChannel *channel; @synchronized(self) { diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm index 8e1a0ee7df..5d384d8fc8 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm @@ -82,8 +82,14 @@ static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f, grpc_channel_args *client_args, stream_engine *cronetEngine) { fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data; + grpc_arg arg; + arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER); + arg.type = GRPC_ARG_INTEGER; + arg.value.integer = 1; + client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1); f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL); + grpc_channel_args_destroy(client_args); GPR_ASSERT(f->client != NULL); } diff --git a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m index 28414b8e39..3da7d533b4 100644 --- a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m +++ b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m @@ -126,6 +126,14 @@ unsigned int parse_h2_length(const char *field) { ((unsigned int)(unsigned char)(field[2])); } +grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *args) { + grpc_arg arg; + arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER); + arg.type = GRPC_ARG_INTEGER; + arg.value.integer = 1; + return grpc_channel_args_copy_and_add(args, &arg, 1); +} + - (void)testInternalError { grpc_call *c; grpc_slice request_payload_slice = @@ -147,8 +155,10 @@ unsigned int parse_h2_length(const char *field) { gpr_join_host_port(&addr, "127.0.0.1", port); grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL); stream_engine *cronetEngine = [Cronet getGlobalEngine]; + grpc_channel_args *client_args = add_disable_client_authority_filter_args(NULL); grpc_channel *client = - grpc_cronet_secure_channel_create(cronetEngine, addr, NULL, NULL); + grpc_cronet_secure_channel_create(cronetEngine, addr, client_args, NULL); + grpc_channel_args_destroy(client_args); cq_verifier *cqv = cq_verifier_create(cq); grpc_op ops[6]; @@ -262,6 +272,8 @@ unsigned int parse_h2_length(const char *field) { arg.type = GRPC_ARG_INTEGER; arg.value.integer = useCoalescing ? 1 : 0; grpc_channel_args *args = grpc_channel_args_copy_and_add(NULL, &arg, 1); + args = add_disable_client_authority_filter_args(args); + grpc_call *c; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); diff --git a/src/objective-c/tests/Podfile b/src/objective-c/tests/Podfile index 6e17d9a7cb..af1a34ab6b 100644 --- a/src/objective-c/tests/Podfile +++ b/src/objective-c/tests/Podfile @@ -43,8 +43,10 @@ end target target_name do pod 'BoringSSL', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c", :inhibit_warnings => true pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" + pod 'gRPC-Core', :path => GRPC_LOCAL_SRC + pod 'gRPC-Core/Cronet-Interface', :path => GRPC_LOCAL_SRC pod 'gRPC-Core/Cronet-Implementation', :path => GRPC_LOCAL_SRC - pod 'gRPC-Core/Cronet-Tests', :path => GRPC_LOCAL_SRC + pod 'gRPC-Core/Tests', :path => GRPC_LOCAL_SRC end end |