Skip to content

Commit 5741508

Browse files
rsa9000gitster
authored andcommitted
http: honor empty http.proxy option to bypass proxy
Curl distinguishes between an empty proxy address and a NULL proxy address. In the first case it completely disables proxy usage, but if the proxy address option is NULL then curl attempts to determine the proxy address from the http_proxy environment variable. According to the documentation, if the http.proxy option is set to an empty string, git should bypass proxy and connect to the server directly: export http_proxy=http://network-proxy/ cd ~/foobar-project git config remote.origin.proxy "" git fetch Previously, proxy host was configured by one line: curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy); Commit 372370f ("http: use credential API to handle proxy authentication", 2016-01-26) parses the proxy option, then extracts the proxy host address and updates the curl configuration, making the previous call a noop: credential_from_url(&proxy_auth, curl_http_proxy); curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host); But if the proxy option is empty then the proxy host field becomes NULL. This forces curl to fall back to detecting the proxy configuration from the environment, causing the http.proxy option to not work anymore. Fix this issue by explicitly handling http.proxy being set the empty string. This also makes the code a bit more clear and should help us avoid such regressions in the future. Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 49800c9 commit 5741508

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

http.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,14 @@ static CURL *get_curl_handle(void)
836836
}
837837
}
838838

839-
if (curl_http_proxy) {
840-
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
839+
if (curl_http_proxy && curl_http_proxy[0] == '\0') {
840+
/*
841+
* Handle case with the empty http.proxy value here to keep
842+
* common code clean.
843+
* NB: empty option disables proxying at all.
844+
*/
845+
curl_easy_setopt(result, CURLOPT_PROXY, "");
846+
} else if (curl_http_proxy) {
841847
#if LIBCURL_VERSION_NUM >= 0x071800
842848
if (starts_with(curl_http_proxy, "socks5h"))
843849
curl_easy_setopt(result,

0 commit comments

Comments
 (0)