aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/client_config/http_connect_handshaker.c
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-09-06 12:50:42 -0700
committerGravatar Mark D. Roth <roth@google.com>2016-09-06 12:50:42 -0700
commit39b5871d7b1da79945c87f98acc4cbbd499ecfba (patch)
tree69a8bfe3a9e210264ab687376b2032421ff34bf7 /src/core/ext/client_config/http_connect_handshaker.c
parent6c3295a5a263d853e3ceb163c7b230c2d87374f6 (diff)
Use http_proxy environment variable instead of URI query param.
Diffstat (limited to 'src/core/ext/client_config/http_connect_handshaker.c')
-rw-r--r--src/core/ext/client_config/http_connect_handshaker.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/ext/client_config/http_connect_handshaker.c b/src/core/ext/client_config/http_connect_handshaker.c
index 55b01bd46e..097465469e 100644
--- a/src/core/ext/client_config/http_connect_handshaker.c
+++ b/src/core/ext/client_config/http_connect_handshaker.c
@@ -40,9 +40,11 @@
#include <grpc/impl/codegen/slice_buffer.h>
#include <grpc/support/string_util.h>
+#include "src/core/ext/client_config/uri_parser.h"
#include "src/core/lib/http/format_request.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/timer.h"
+#include "src/core/lib/support/env.h"
typedef struct http_connect_handshaker {
// Base class. Must be first.
@@ -247,3 +249,26 @@ grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server,
gpr_ref_init(&handshaker->refcount, 1);
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:
+ grpc_uri_destroy(uri);
+ return proxy_name;
+}