Web lists-archives.com

[PATCH] http: honnor empty http.proxy option to bypass proxy

Curl distinguish between empty proxy address and NULL proxy address. In
the first case it completly disable proxy usage, but if proxy address
option is NULL then curl attempt to determine proxy address from
http_proxy environment variable.

According to documentation, if http.proxy configured to empty string
then git should bypass proxy and connects 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 auth...) parses
proxy option, extracts proxy host address and additionaly updates curl

    credential_from_url(&proxy_auth, curl_http_proxy);
    curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host);

But if proxy option is empty then proxy host field become NULL this
force curl to fallback to proxy configuration detection from
environment. This caused empty http.proxy option not working any more.

Avoid setting NULL CURLOPT_PROXY from proxy_auth.host to fix this issue.

Signed-off-by: Sergey Ryazanov <ryazanov.s.a@xxxxxxxxx>
 http.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/http.c b/http.c
index 96d84bb..bf0e709 100644
--- a/http.c
+++ b/http.c
@@ -861,7 +861,12 @@ static CURL *get_curl_handle(void)
-		curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host);
+		/*
+		 * Avoid setting CURLOPT_PROXY to NULL if empty http.proxy
+		 * option configured.
+		 */
+		if (proxy_auth.host)
+			curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host);
 #if LIBCURL_VERSION_NUM >= 0x071304
 		var_override(&curl_no_proxy, getenv("NO_PROXY"));
 		var_override(&curl_no_proxy, getenv("no_proxy"));