|
|
|
@ -36,6 +36,7 @@ |
|
|
|
|
#include "src/core/lib/gpr/env.h" |
|
|
|
|
#include "src/core/lib/gpr/string.h" |
|
|
|
|
#include "src/core/lib/gprpp/host_port.h" |
|
|
|
|
#include "src/core/lib/iomgr/resolve_address.h" |
|
|
|
|
#include "src/core/lib/slice/b64.h" |
|
|
|
|
#include "src/core/lib/uri/uri_parser.h" |
|
|
|
|
|
|
|
|
@ -107,6 +108,17 @@ done: |
|
|
|
|
return proxy_name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Adds the default port if target does not contain a port.
|
|
|
|
|
std::string MaybeAddDefaultPort(absl::string_view target) { |
|
|
|
|
absl::string_view host; |
|
|
|
|
absl::string_view port; |
|
|
|
|
SplitHostPort(target, &host, &port); |
|
|
|
|
if (port.empty()) { |
|
|
|
|
return JoinHostPort(host, kDefaultSecurePortInt); |
|
|
|
|
} |
|
|
|
|
return std::string(target); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class HttpProxyMapper : public ProxyMapperInterface { |
|
|
|
|
public: |
|
|
|
|
bool MapName(const char* server_uri, const grpc_channel_args* args, |
|
|
|
@ -118,6 +130,7 @@ class HttpProxyMapper : public ProxyMapperInterface { |
|
|
|
|
*name_to_resolve = GetHttpProxyServer(args, &user_cred); |
|
|
|
|
if (*name_to_resolve == nullptr) return false; |
|
|
|
|
char* no_proxy_str = nullptr; |
|
|
|
|
std::string server_target; |
|
|
|
|
absl::StatusOr<URI> uri = URI::Parse(server_uri); |
|
|
|
|
if (!uri.ok() || uri->path().empty()) { |
|
|
|
|
gpr_log(GPR_ERROR, |
|
|
|
@ -173,10 +186,12 @@ class HttpProxyMapper : public ProxyMapperInterface { |
|
|
|
|
if (!use_proxy) goto no_use_proxy; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
server_target = |
|
|
|
|
MaybeAddDefaultPort(absl::StripPrefix(uri->path(), "/")).c_str(); |
|
|
|
|
grpc_arg args_to_add[2]; |
|
|
|
|
args_to_add[0] = grpc_channel_arg_string_create( |
|
|
|
|
const_cast<char*>(GRPC_ARG_HTTP_CONNECT_SERVER), |
|
|
|
|
const_cast<char*>(absl::StripPrefix(uri->path(), "/").data())); |
|
|
|
|
const_cast<char*>(server_target.c_str())); |
|
|
|
|
if (user_cred != nullptr) { |
|
|
|
|
/* Use base64 encoding for user credentials as stated in RFC 7617 */ |
|
|
|
|
char* encoded_user_cred = |
|
|
|
|