git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] http: honor no_http env variable to bypass proxy

From
Jiang Xin <worldhello.net@gmail.com>
Date
Feb 29, 2016, 15:16 UTC
Message-ID
<5652e025323b60ccf5a59bcbdc7266d4f4e32fc4.1456758964.git.xin.jiang@huawei.com>
From: Jiang Xin <xin.jiang@huawei.com>
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 <xin.jiang@huawei.com>
---
 http.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/http.c b/http.c
index 1d5e3bb..69da445 100644
--- a/http.c
+++ b/http.c
@@ -70,6 +70,7 @@ static long curl_low_speed_limit = -1;
 static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
+static const char *curl_no_proxy;
 static const char *http_proxy_authmethod;
 static struct {
 	const char *name;
@@ -624,6 +625,11 @@ static CURL *get_curl_handle(void)
 		}
 
 		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"));
+		curl_easy_setopt(result, CURLOPT_NOPROXY, curl_no_proxy);
+#endif
 	}
 	init_curl_proxy_auth(result);
 
-- 
2.8.0.rc0.1.g9eb3984.dirty
Next: Junio C Hamano
Message 1 of 5 in “http: honor no_http env variable to bypass proxy”
  1. http: honor no_http env variable to bypass proxyJiang Xin, Feb 29, 2016
  2. Junio C HamanoFeb 29, 2016
  3. Junio C HamanoMar 7, 2016
  4. Elia PintoMar 10, 2016
  5. Elia PintoMar 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.