Skip to content

Commit d445fda

Browse files
jiangxingitster
authored andcommitted
http: honor no_http env variable to bypass proxy
Curl and its families honor several proxy related environment variables: * http_proxy and https_proxy define proxy for http/https connections. * no_proxy (a comma separated hosts) defines hosts bypass the proxy. This command will bypass the bad-proxy and connect to the host directly: no_proxy=* https_proxy=http://bad-proxy/ \ curl -sk https://google.com/ Before commit 372370f (http: use credential API to handle proxy auth...), Environment variable "no_proxy" will take effect if the config variable "http.proxy" is not set. So the following comamnd won't fail if not behind a firewall. no_proxy=* https_proxy=http://bad-proxy/ \ git ls-remote https://github.com/git/git But commit 372370f not only read git config variable "http.proxy", but also read "http_proxy" and "https_proxy" environment variables, and set the curl option using: curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host); This caused "no_proxy" environment variable not working any more. Set extra curl option "CURLOPT_NOPROXY" will fix this issue. Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 372370f commit d445fda

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

http.c

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static long curl_low_speed_limit = -1;
6262
static long curl_low_speed_time = -1;
6363
static int curl_ftp_no_epsv;
6464
static const char *curl_http_proxy;
65+
static const char *curl_no_proxy;
6566
static const char *http_proxy_authmethod;
6667
static struct {
6768
const char *name;
@@ -594,6 +595,11 @@ static CURL *get_curl_handle(void)
594595
}
595596

596597
curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host);
598+
#if LIBCURL_VERSION_NUM >= 0x071304
599+
var_override(&curl_no_proxy, getenv("NO_PROXY"));
600+
var_override(&curl_no_proxy, getenv("no_proxy"));
601+
curl_easy_setopt(result, CURLOPT_NOPROXY, curl_no_proxy);
602+
#endif
597603
}
598604
init_curl_proxy_auth(result);
599605

0 commit comments

Comments
 (0)