Go to the documentation of this file.
29 #include "absl/container/inlined_vector.h"
30 #include "absl/status/status.h"
31 #include "absl/status/statusor.h"
32 #include "absl/strings/match.h"
33 #include "absl/strings/str_cat.h"
34 #include "absl/strings/str_split.h"
35 #include "absl/strings/string_view.h"
36 #include "absl/strings/strip.h"
66 char* proxy_name =
nullptr;
67 char** authority_strs =
nullptr;
68 size_t authority_nstrs;
77 auto uri_str = UniquePtr<char>(
79 if (uri_str ==
nullptr) uri_str = UniquePtr<char>(
gpr_getenv(
"grpc_proxy"));
80 if (uri_str ==
nullptr) uri_str = UniquePtr<char>(
gpr_getenv(
"https_proxy"));
81 if (uri_str ==
nullptr) uri_str = UniquePtr<char>(
gpr_getenv(
"http_proxy"));
82 if (uri_str ==
nullptr)
return nullptr;
84 if (uri_str.get()[0] ==
'\0')
return nullptr;
88 uri.
status().ToString().c_str());
91 if (uri->
scheme() !=
"http") {
100 if (authority_nstrs == 1) {
102 proxy_name = authority_strs[0];
103 }
else if (authority_nstrs == 2) {
105 *user_cred = authority_strs[0];
106 proxy_name = authority_strs[1];
110 for (
size_t i = 0;
i < authority_nstrs;
i++) {
113 proxy_name =
nullptr;
134 char** name_to_resolve,
139 char* user_cred =
nullptr;
140 *name_to_resolve = GetHttpProxyServer(
args, &user_cred);
141 if (*name_to_resolve ==
nullptr)
return false;
144 auto no_use_proxy = [&]() {
146 *name_to_resolve =
nullptr;
150 if (!uri.
ok() || uri->path().empty()) {
152 "'http_proxy' environment variable set, but cannot "
153 "parse server URI '%s' -- not using proxy. Error: %s",
155 return no_use_proxy();
157 if (uri->scheme() ==
"unix") {
160 return no_use_proxy();
164 if (no_proxy_str ==
nullptr) {
167 if (no_proxy_str !=
nullptr) {
168 bool use_proxy =
true;
174 "unable to split host and port, not checking no_proxy list for "
178 std::vector<absl::string_view> no_proxy_hosts =
180 for (
const auto& no_proxy_entry : no_proxy_hosts) {
188 if (!use_proxy)
return no_use_proxy();
196 const_cast<char*
>(server_target.c_str())));
198 if (user_cred !=
nullptr) {
200 auto encoded_user_cred =
203 absl::StrCat(
"Proxy-Authorization:Basic ", encoded_user_cred.get());
206 const_cast<char*
>(
header.c_str())));
strings_internal::Splitter< typename strings_internal::SelectDelimiter< Delimiter >::type, AllowEmpty, absl::string_view > StrSplit(strings_internal::ConvertibleToStringView text, Delimiter d)
char * grpc_channel_args_find_string(const grpc_channel_args *args, const char *name)
bool MapName(const char *server_uri, const grpc_channel_args *args, char **name_to_resolve, grpc_channel_args **new_args) override
void gpr_string_split(const char *input, const char *sep, char ***strs, size_t *nstrs)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
GPRAPI void gpr_free(void *ptr)
bool SplitHostPort(absl::string_view name, absl::string_view *host, absl::string_view *port)
#define GRPC_ARG_HTTP_CONNECT_HEADERS
grpc_arg grpc_channel_arg_string_create(char *name, char *value)
ABSL_MUST_USE_RESULT absl::string_view StripPrefix(absl::string_view str, absl::string_view prefix)
static absl::StatusOr< URI > Parse(absl::string_view uri_text)
bool grpc_channel_args_find_bool(const grpc_channel_args *args, const char *name, bool default_value)
char * gpr_getenv(const char *name)
const std::string & authority() const
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
#define GRPC_ARG_HTTP_PROXY
std::string JoinHostPort(absl::string_view host, int port)
void push_back(const_reference v)
struct absl::base_internal::@2940::AllocList::Header header
size_type size() const noexcept
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
char * grpc_base64_encode(const void *vdata, size_t data_size, int url_safe, int multiline)
const std::string & scheme() const
ABSL_MUST_USE_RESULT bool ok() const
bool EndsWithIgnoreCase(absl::string_view text, absl::string_view suffix) noexcept
static void Register(bool at_start, std::unique_ptr< ProxyMapperInterface > mapper)
constexpr int kDefaultSecurePortInt
GPRAPI char * gpr_strdup(const char *src)
void RegisterHttpProxyMapper()
#define GRPC_ARG_ENABLE_HTTP_PROXY
grpc_channel_args * grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add)
const Status & status() const &
#define GRPC_ARG_HTTP_CONNECT_SERVER
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:02