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

5 messages from 2016-02-29 to 2016-03-10. Participants: Jiang Xin, Junio C Hamano, Elia Pinto.
Thread: https://gitlist.dev/t/41568

## Jiang Xin, 2016-02-29 15:16

Subject: [PATCH] http: honor no_http env variable to bypass proxy
Message-ID: <5652e025323b60ccf5a59bcbdc7266d4f4e32fc4.1456758964.git.xin.jiang@huawei.com>
URL: https://gitlist.dev/e/5652e025323b60ccf5a59bcbdc7266d4f4e32fc4.1456758964.git.xin.jiang%40huawei.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

```

## Junio C Hamano, 2016-02-29 19:29

Subject: Re: [PATCH] http: honor no_http env variable to bypass proxy
Message-ID: <xmqqio179uxn.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqio179uxn.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <5652e025323b60ccf5a59bcbdc7266d4f4e32fc4.1456758964.git.xin.jiang@huawei.com>

```
Jiang Xin <worldhello.net@gmail.com> writes:

> 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(+)

Sounds sensible; I am guessing that this is 2.8.0-rc0 regression
that we need to fast-track?

Knut, does this look good?

Thanks.

> 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);

```

## Junio C Hamano, 2016-03-07 20:33

Subject: Re: [PATCH] http: honor no_http env variable to bypass proxy
Message-ID: <xmqqr3fmni4d.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqr3fmni4d.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <xmqqio179uxn.fsf@gitster.mtv.corp.google.com>

```
Junio C Hamano <gitster@pobox.com> writes:

Second call for help.  I hate having to revert 30f302f7 (Merge
branch 'kf/http-proxy-auth-methods', 2016-02-03) this late in the
cycle.

> Jiang Xin <worldhello.net@gmail.com> writes:
>
>> 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(+)
>
> Sounds sensible; I am guessing that this is 2.8.0-rc0 regression
> that we need to fast-track?
>
> Knut, does this look good?
>
> Thanks.
>
>> 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);

```

## Elia Pinto, 2016-03-10 08:46

Subject: Re: [PATCH] http: honor no_http env variable to bypass proxy
Message-ID: <CA+EOSBkfj1bt+yf2KQTzVoAPRkbB6MGUaJEmJV54Efz+0FOOwg@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BEOSBkfj1bt%2Byf2KQTzVoAPRkbB6MGUaJEmJV54Efz%2B0FOOwg%40mail.gmail.com
In-Reply-To: <5652e025323b60ccf5a59bcbdc7266d4f4e32fc4.1456758964.git.xin.jiang@huawei.com>

```
2016-02-29 16:16 GMT+01:00 Jiang Xin <worldhello.net@gmail.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>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.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
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Elia Pinto, 2016-03-10 08:50

Subject: Re: [PATCH] http: honor no_http env variable to bypass proxy
Message-ID: <CA+EOSBmaWNrpvPiiYZJ270UeAbKVcBS2d2Tr5byoW4HX9R79Hw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BEOSBmaWNrpvPiiYZJ270UeAbKVcBS2d2Tr5byoW4HX9R79Hw%40mail.gmail.com
In-Reply-To: <xmqqr3fmni4d.fsf@gitster.mtv.corp.google.com>

```
2016-03-07 21:33 GMT+01:00 Junio C Hamano <gitster@pobox.com>:
> Junio C Hamano <gitster@pobox.com> writes:
>
> Second call for help.  I hate having to revert 30f302f7 (Merge
> branch 'kf/http-proxy-auth-methods', 2016-02-03) this late in the
> cycle.
Ok. I made the original merge commit for master. So,  if it is
sufficient, for me the patch is correct.

I am sorry for the delay in the response.

Best
>
>> Jiang Xin <worldhello.net@gmail.com> writes:
>>
>>> 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(+)
>>
>> Sounds sensible; I am guessing that this is 2.8.0-rc0 regression
>> that we need to fast-track?
>>
>> Knut, does this look good?
>>
>> Thanks.
>>
>>> 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);
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```
