From 79f2a246447aaf1117744a053ee6e417447b40ee Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 17 Jan 2017 14:13:33 -0800 Subject: Add proxy mapper hook. --- tools/doxygen/Doxyfile.core.internal | 4 ++++ tools/run_tests/generated/sources_and_headers.json | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'tools') diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 4591aa50e3..64ec0d475d 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -906,6 +906,10 @@ src/core/ext/client_channel/lb_policy_registry.c \ src/core/ext/client_channel/lb_policy_registry.h \ src/core/ext/client_channel/parse_address.c \ src/core/ext/client_channel/parse_address.h \ +src/core/ext/client_channel/proxy_mapper.c \ +src/core/ext/client_channel/proxy_mapper.h \ +src/core/ext/client_channel/proxy_mapper_registry.c \ +src/core/ext/client_channel/proxy_mapper_registry.h \ src/core/ext/client_channel/resolver.c \ src/core/ext/client_channel/resolver.h \ src/core/ext/client_channel/resolver_factory.c \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 1a3345cb95..4005284593 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7122,6 +7122,8 @@ "src/core/ext/client_channel/lb_policy_factory.h", "src/core/ext/client_channel/lb_policy_registry.h", "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/proxy_mapper.h", + "src/core/ext/client_channel/proxy_mapper_registry.h", "src/core/ext/client_channel/resolver.h", "src/core/ext/client_channel/resolver_factory.h", "src/core/ext/client_channel/resolver_registry.h", @@ -7154,6 +7156,10 @@ "src/core/ext/client_channel/lb_policy_registry.h", "src/core/ext/client_channel/parse_address.c", "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/proxy_mapper.c", + "src/core/ext/client_channel/proxy_mapper.h", + "src/core/ext/client_channel/proxy_mapper_registry.c", + "src/core/ext/client_channel/proxy_mapper_registry.h", "src/core/ext/client_channel/resolver.c", "src/core/ext/client_channel/resolver.h", "src/core/ext/client_channel/resolver_factory.c", -- cgit v1.2.3 From d58a985a56a561df49e668af1153c69ae5b8f4ac Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 18 Jan 2017 08:28:57 -0800 Subject: Move detection of HTTP CONNECT proxy from DNS resolver to client channel. --- BUILD | 2 + CMakeLists.txt | 4 ++ Makefile | 4 ++ binding.gyp | 1 + build.yaml | 2 + config.m4 | 1 + gRPC-Core.podspec | 3 + grpc.gemspec | 2 + package.xml | 2 + src/core/ext/client_channel/client_channel.c | 26 ++++++++- .../ext/client_channel/http_connect_handshaker.c | 24 -------- .../ext/client_channel/http_connect_handshaker.h | 7 --- src/core/ext/client_channel/http_proxy.c | 68 ++++++++++++++++++++++ src/core/ext/client_channel/http_proxy.h | 41 +++++++++++++ src/core/ext/resolver/dns/native/dns_resolver.c | 15 +---- src/python/grpcio/grpc_core_dependencies.py | 1 + tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/generated/sources_and_headers.json | 3 + vsprojects/vcxproj/grpc/grpc.vcxproj | 3 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 6 ++ .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 3 + .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 6 ++ 22 files changed, 180 insertions(+), 46 deletions(-) create mode 100644 src/core/ext/client_channel/http_proxy.c create mode 100644 src/core/ext/client_channel/http_proxy.h (limited to 'tools') diff --git a/BUILD b/BUILD index bbde04674b..bd53ae5b7f 100644 --- a/BUILD +++ b/BUILD @@ -664,6 +664,7 @@ grpc_cc_library( "src/core/ext/client_channel/connector.c", "src/core/ext/client_channel/default_initial_connect_string.c", "src/core/ext/client_channel/http_connect_handshaker.c", + "src/core/ext/client_channel/http_proxy.c", "src/core/ext/client_channel/initial_connect_string.c", "src/core/ext/client_channel/lb_policy.c", "src/core/ext/client_channel/lb_policy_factory.c", @@ -681,6 +682,7 @@ grpc_cc_library( "src/core/ext/client_channel/client_channel_factory.h", "src/core/ext/client_channel/connector.h", "src/core/ext/client_channel/http_connect_handshaker.h", + "src/core/ext/client_channel/http_proxy.h", "src/core/ext/client_channel/initial_connect_string.h", "src/core/ext/client_channel/lb_policy.h", "src/core/ext/client_channel/lb_policy_factory.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d67736c13..512dc4739c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -465,6 +465,7 @@ add_library(grpc src/core/ext/client_channel/connector.c src/core/ext/client_channel/default_initial_connect_string.c src/core/ext/client_channel/http_connect_handshaker.c + src/core/ext/client_channel/http_proxy.c src/core/ext/client_channel/initial_connect_string.c src/core/ext/client_channel/lb_policy.c src/core/ext/client_channel/lb_policy_factory.c @@ -724,6 +725,7 @@ add_library(grpc_cronet src/core/ext/client_channel/connector.c src/core/ext/client_channel/default_initial_connect_string.c src/core/ext/client_channel/http_connect_handshaker.c + src/core/ext/client_channel/http_proxy.c src/core/ext/client_channel/initial_connect_string.c src/core/ext/client_channel/lb_policy.c src/core/ext/client_channel/lb_policy_factory.c @@ -982,6 +984,7 @@ add_library(grpc_unsecure src/core/ext/client_channel/connector.c src/core/ext/client_channel/default_initial_connect_string.c src/core/ext/client_channel/http_connect_handshaker.c + src/core/ext/client_channel/http_proxy.c src/core/ext/client_channel/initial_connect_string.c src/core/ext/client_channel/lb_policy.c src/core/ext/client_channel/lb_policy_factory.c @@ -1428,6 +1431,7 @@ add_library(grpc++_cronet src/core/ext/client_channel/connector.c src/core/ext/client_channel/default_initial_connect_string.c src/core/ext/client_channel/http_connect_handshaker.c + src/core/ext/client_channel/http_proxy.c src/core/ext/client_channel/initial_connect_string.c src/core/ext/client_channel/lb_policy.c src/core/ext/client_channel/lb_policy_factory.c diff --git a/Makefile b/Makefile index 184bdaf58b..39a712a2a4 100644 --- a/Makefile +++ b/Makefile @@ -2815,6 +2815,7 @@ LIBGRPC_SRC = \ src/core/ext/client_channel/connector.c \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ + src/core/ext/client_channel/http_proxy.c \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/lb_policy.c \ src/core/ext/client_channel/lb_policy_factory.c \ @@ -3092,6 +3093,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/client_channel/connector.c \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ + src/core/ext/client_channel/http_proxy.c \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/lb_policy.c \ src/core/ext/client_channel/lb_policy_factory.c \ @@ -3608,6 +3610,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/client_channel/connector.c \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ + src/core/ext/client_channel/http_proxy.c \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/lb_policy.c \ src/core/ext/client_channel/lb_policy_factory.c \ @@ -4166,6 +4169,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/client_channel/connector.c \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ + src/core/ext/client_channel/http_proxy.c \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/lb_policy.c \ src/core/ext/client_channel/lb_policy_factory.c \ diff --git a/binding.gyp b/binding.gyp index 479403ed21..d2edda16cb 100644 --- a/binding.gyp +++ b/binding.gyp @@ -768,6 +768,7 @@ 'src/core/ext/client_channel/connector.c', 'src/core/ext/client_channel/default_initial_connect_string.c', 'src/core/ext/client_channel/http_connect_handshaker.c', + 'src/core/ext/client_channel/http_proxy.c', 'src/core/ext/client_channel/initial_connect_string.c', 'src/core/ext/client_channel/lb_policy.c', 'src/core/ext/client_channel/lb_policy_factory.c', diff --git a/build.yaml b/build.yaml index 1072bfcb63..3d7ffd6938 100644 --- a/build.yaml +++ b/build.yaml @@ -389,6 +389,7 @@ filegroups: - src/core/ext/client_channel/client_channel_factory.h - src/core/ext/client_channel/connector.h - src/core/ext/client_channel/http_connect_handshaker.h + - src/core/ext/client_channel/http_proxy.h - src/core/ext/client_channel/initial_connect_string.h - src/core/ext/client_channel/lb_policy.h - src/core/ext/client_channel/lb_policy_factory.h @@ -408,6 +409,7 @@ filegroups: - src/core/ext/client_channel/connector.c - src/core/ext/client_channel/default_initial_connect_string.c - src/core/ext/client_channel/http_connect_handshaker.c + - src/core/ext/client_channel/http_proxy.c - src/core/ext/client_channel/initial_connect_string.c - src/core/ext/client_channel/lb_policy.c - src/core/ext/client_channel/lb_policy_factory.c diff --git a/config.m4 b/config.m4 index 85549e5f42..2e08149fd0 100644 --- a/config.m4 +++ b/config.m4 @@ -254,6 +254,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/client_channel/connector.c \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ + src/core/ext/client_channel/http_proxy.c \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/lb_policy.c \ src/core/ext/client_channel/lb_policy_factory.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 1eb178931d..1add33eadd 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -400,6 +400,7 @@ Pod::Spec.new do |s| 'src/core/ext/client_channel/client_channel_factory.h', 'src/core/ext/client_channel/connector.h', 'src/core/ext/client_channel/http_connect_handshaker.h', + 'src/core/ext/client_channel/http_proxy.h', 'src/core/ext/client_channel/initial_connect_string.h', 'src/core/ext/client_channel/lb_policy.h', 'src/core/ext/client_channel/lb_policy_factory.h', @@ -606,6 +607,7 @@ Pod::Spec.new do |s| 'src/core/ext/client_channel/connector.c', 'src/core/ext/client_channel/default_initial_connect_string.c', 'src/core/ext/client_channel/http_connect_handshaker.c', + 'src/core/ext/client_channel/http_proxy.c', 'src/core/ext/client_channel/initial_connect_string.c', 'src/core/ext/client_channel/lb_policy.c', 'src/core/ext/client_channel/lb_policy_factory.c', @@ -812,6 +814,7 @@ Pod::Spec.new do |s| 'src/core/ext/client_channel/client_channel_factory.h', 'src/core/ext/client_channel/connector.h', 'src/core/ext/client_channel/http_connect_handshaker.h', + 'src/core/ext/client_channel/http_proxy.h', 'src/core/ext/client_channel/initial_connect_string.h', 'src/core/ext/client_channel/lb_policy.h', 'src/core/ext/client_channel/lb_policy_factory.h', diff --git a/grpc.gemspec b/grpc.gemspec index cfc0c35aa3..4ed91f1136 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -317,6 +317,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/client_channel/client_channel_factory.h ) s.files += %w( src/core/ext/client_channel/connector.h ) s.files += %w( src/core/ext/client_channel/http_connect_handshaker.h ) + s.files += %w( src/core/ext/client_channel/http_proxy.h ) s.files += %w( src/core/ext/client_channel/initial_connect_string.h ) s.files += %w( src/core/ext/client_channel/lb_policy.h ) s.files += %w( src/core/ext/client_channel/lb_policy_factory.h ) @@ -523,6 +524,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/client_channel/connector.c ) s.files += %w( src/core/ext/client_channel/default_initial_connect_string.c ) s.files += %w( src/core/ext/client_channel/http_connect_handshaker.c ) + s.files += %w( src/core/ext/client_channel/http_proxy.c ) s.files += %w( src/core/ext/client_channel/initial_connect_string.c ) s.files += %w( src/core/ext/client_channel/lb_policy.c ) s.files += %w( src/core/ext/client_channel/lb_policy_factory.c ) diff --git a/package.xml b/package.xml index aa1894f408..42cd6f7157 100644 --- a/package.xml +++ b/package.xml @@ -326,6 +326,7 @@ + @@ -532,6 +533,7 @@ + diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 2f25fef9a7..3c03aa1eac 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -43,6 +43,8 @@ #include #include +#include "src/core/ext/client_channel/http_connect_handshaker.h" +#include "src/core/ext/client_channel/http_proxy.h" #include "src/core/ext/client_channel/lb_policy_registry.h" #include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/ext/client_channel/subchannel.h" @@ -150,6 +152,10 @@ static void *method_parameters_create_from_json(const grpc_json *json) { */ typedef struct client_channel_channel_data { + /** server name */ + char *server_name; + /** HTTP CONNECT proxy to use, if any */ + char *proxy_name; /** resolver for this channel */ grpc_resolver *resolver; /** have we started resolving this channel */ @@ -310,6 +316,17 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, // Use pick_first if nothing was specified and we didn't select grpclb // above. if (lb_policy_name == NULL) lb_policy_name = "pick_first"; + // If using a proxy, add channel arg for HTTP CONNECT server. + if (chand->proxy_name != NULL) { + grpc_arg new_arg; + new_arg.key = GRPC_ARG_HTTP_CONNECT_SERVER; + new_arg.type = GRPC_ARG_STRING; + new_arg.value.string = chand->server_name; + grpc_channel_args *tmp_args = chand->resolver_result; + chand->resolver_result = + grpc_channel_args_copy_and_add(chand->resolver_result, &new_arg, 1); + grpc_channel_args_destroy(exec_ctx, tmp_args); + } // Instantiate LB policy. grpc_lb_policy_args lb_policy_args; lb_policy_args.args = chand->resolver_result; @@ -528,8 +545,12 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); GPR_ASSERT(arg != NULL); GPR_ASSERT(arg->type == GRPC_ARG_STRING); + chand->server_name = gpr_strdup(arg->value.string); + chand->proxy_name = grpc_get_http_proxy_server(); + char* name_to_resolve = chand->proxy_name == NULL + ? chand->server_name : chand->proxy_name; chand->resolver = - grpc_resolver_create(exec_ctx, arg->value.string, args->channel_args, + grpc_resolver_create(exec_ctx, name_to_resolve, args->channel_args, chand->interested_parties); if (chand->resolver == NULL) { return GRPC_ERROR_CREATE("resolver creation failed"); @@ -541,7 +562,8 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx, static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) { channel_data *chand = elem->channel_data; - + gpr_free(chand->server_name); + gpr_free(chand->proxy_name); if (chand->resolver != NULL) { grpc_resolver_shutdown(exec_ctx, chand->resolver); GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); diff --git a/src/core/ext/client_channel/http_connect_handshaker.c b/src/core/ext/client_channel/http_connect_handshaker.c index a4ff379784..c8f614681f 100644 --- a/src/core/ext/client_channel/http_connect_handshaker.c +++ b/src/core/ext/client_channel/http_connect_handshaker.c @@ -354,30 +354,6 @@ static grpc_handshaker* grpc_http_connect_handshaker_create() { return &handshaker->base; } -char* grpc_get_http_proxy_server() { - char* uri_str = gpr_getenv("http_proxy"); - if (uri_str == NULL) return NULL; - grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); - char* proxy_name = NULL; - if (uri == NULL || uri->authority == NULL) { - gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); - goto done; - } - if (strcmp(uri->scheme, "http") != 0) { - gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme); - goto done; - } - if (strchr(uri->authority, '@') != NULL) { - gpr_log(GPR_ERROR, "userinfo not supported in proxy URI"); - goto done; - } - proxy_name = gpr_strdup(uri->authority); -done: - gpr_free(uri_str); - grpc_uri_destroy(uri); - return proxy_name; -} - // // handshaker factory // diff --git a/src/core/ext/client_channel/http_connect_handshaker.h b/src/core/ext/client_channel/http_connect_handshaker.h index a665bfc7e5..8b1735b2ce 100644 --- a/src/core/ext/client_channel/http_connect_handshaker.h +++ b/src/core/ext/client_channel/http_connect_handshaker.h @@ -34,9 +34,6 @@ #ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_CONNECT_HANDSHAKER_H #define GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_CONNECT_HANDSHAKER_H -#include "src/core/lib/channel/handshaker.h" -#include "src/core/lib/http/parser.h" - /// Channel arg indicating HTTP CONNECT server (string). #define GRPC_ARG_HTTP_CONNECT_SERVER "grpc.http_connect_server" @@ -45,10 +42,6 @@ /// seperated by colons. #define GRPC_ARG_HTTP_CONNECT_HEADERS "grpc.http_connect_headers" -/// Returns the name of the proxy to use, or NULL if no proxy is configured. -/// Caller takes ownership of result. -char* grpc_get_http_proxy_server(); - /// Registers handshaker factory. void grpc_http_connect_register_handshaker_factory(); diff --git a/src/core/ext/client_channel/http_proxy.c b/src/core/ext/client_channel/http_proxy.c new file mode 100644 index 0000000000..9a6c818c4e --- /dev/null +++ b/src/core/ext/client_channel/http_proxy.c @@ -0,0 +1,68 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/http_proxy.h" + +#include +#include + +#include +#include +#include + +#include "src/core/ext/client_channel/uri_parser.h" +#include "src/core/lib/support/env.h" + +char* grpc_get_http_proxy_server() { + char* uri_str = gpr_getenv("http_proxy"); + if (uri_str == NULL) return NULL; + grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); + char* proxy_name = NULL; + if (uri == NULL || uri->authority == NULL) { + gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); + goto done; + } + if (strcmp(uri->scheme, "http") != 0) { + gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme); + goto done; + } + if (strchr(uri->authority, '@') != NULL) { + gpr_log(GPR_ERROR, "userinfo not supported in proxy URI"); + goto done; + } + proxy_name = gpr_strdup(uri->authority); +done: + gpr_free(uri_str); + grpc_uri_destroy(uri); + return proxy_name; +} diff --git a/src/core/ext/client_channel/http_proxy.h b/src/core/ext/client_channel/http_proxy.h new file mode 100644 index 0000000000..0d77ae253b --- /dev/null +++ b/src/core/ext/client_channel/http_proxy.h @@ -0,0 +1,41 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H +#define GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H + +/// Returns the name of the proxy to use, or NULL if no proxy is configured. +/// Caller takes ownership of result. +char* grpc_get_http_proxy_server(); + +#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H */ diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index aaf52dc430..bf2f4e5ee4 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -37,7 +37,6 @@ #include #include -#include "src/core/ext/client_channel/http_connect_handshaker.h" #include "src/core/ext/client_channel/lb_policy_registry.h" #include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/lib/channel/channel_args.h" @@ -263,24 +262,14 @@ static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx, // Get name from args. char *path = args->uri->path; if (path[0] == '/') ++path; - // Get proxy name, if any. - char *proxy_name = grpc_get_http_proxy_server(); - grpc_arg new_arg; - if (proxy_name != NULL) { - new_arg.key = GRPC_ARG_HTTP_CONNECT_SERVER; - new_arg.type = GRPC_ARG_STRING; - new_arg.value.string = path; - } // Create resolver. dns_resolver *r = gpr_malloc(sizeof(dns_resolver)); memset(r, 0, sizeof(*r)); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &dns_resolver_vtable); - r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name; + r->name_to_resolve = gpr_strdup(path); r->default_port = gpr_strdup(default_port); - r->channel_args = proxy_name == NULL - ? grpc_channel_args_copy(args->args) - : grpc_channel_args_copy_and_add(args->args, &new_arg, 1); + r->channel_args = grpc_channel_args_copy(args->args); r->interested_parties = grpc_pollset_set_create(); if (args->pollset_set != NULL) { grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index e27e9e181d..22c943da30 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -248,6 +248,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/client_channel/connector.c', 'src/core/ext/client_channel/default_initial_connect_string.c', 'src/core/ext/client_channel/http_connect_handshaker.c', + 'src/core/ext/client_channel/http_proxy.c', 'src/core/ext/client_channel/initial_connect_string.c', 'src/core/ext/client_channel/lb_policy.c', 'src/core/ext/client_channel/lb_policy_factory.c', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 4591aa50e3..d7fc4e6c1b 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -896,6 +896,8 @@ src/core/ext/client_channel/connector.h \ src/core/ext/client_channel/default_initial_connect_string.c \ src/core/ext/client_channel/http_connect_handshaker.c \ src/core/ext/client_channel/http_connect_handshaker.h \ +src/core/ext/client_channel/http_proxy.c \ +src/core/ext/client_channel/http_proxy.h \ src/core/ext/client_channel/initial_connect_string.c \ src/core/ext/client_channel/initial_connect_string.h \ src/core/ext/client_channel/lb_policy.c \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 1a3345cb95..8ed88f25b4 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7117,6 +7117,7 @@ "src/core/ext/client_channel/client_channel_factory.h", "src/core/ext/client_channel/connector.h", "src/core/ext/client_channel/http_connect_handshaker.h", + "src/core/ext/client_channel/http_proxy.h", "src/core/ext/client_channel/initial_connect_string.h", "src/core/ext/client_channel/lb_policy.h", "src/core/ext/client_channel/lb_policy_factory.h", @@ -7144,6 +7145,8 @@ "src/core/ext/client_channel/default_initial_connect_string.c", "src/core/ext/client_channel/http_connect_handshaker.c", "src/core/ext/client_channel/http_connect_handshaker.h", + "src/core/ext/client_channel/http_proxy.c", + "src/core/ext/client_channel/http_proxy.h", "src/core/ext/client_channel/initial_connect_string.c", "src/core/ext/client_channel/initial_connect_string.h", "src/core/ext/client_channel/lb_policy.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index c159db63f5..ade6fe1aac 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -449,6 +449,7 @@ + @@ -831,6 +832,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 1e099f3285..6a999b6d73 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -523,6 +523,9 @@ src\core\ext\client_channel + + src\core\ext\client_channel + src\core\ext\client_channel @@ -1196,6 +1199,9 @@ src\core\ext\client_channel + + src\core\ext\client_channel + src\core\ext\client_channel diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index dcb943a3a1..fa0651bab2 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -416,6 +416,7 @@ + @@ -751,6 +752,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index ac84e0188c..3601ba2ea1 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -454,6 +454,9 @@ src\core\ext\client_channel + + src\core\ext\client_channel + src\core\ext\client_channel @@ -1040,6 +1043,9 @@ src\core\ext\client_channel + + src\core\ext\client_channel + src\core\ext\client_channel -- cgit v1.2.3