# [PATCH] Improve http proxy support

5 messages from 2012-02-22 to 2012-02-23. Participants: Nelson Benítez León, Matthieu Moy, Thomas Rast.
Thread: https://gitlist.dev/t/29692

## Nelson Benítez León, 2012-02-22 14:04

Subject: [PATCH] Improve http proxy support
Message-ID: <CAAUd640GaLz4TGs_Lz6KbSFK0VcEVxGfO6PpSCdhch+fYwVovw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAUd640GaLz4TGs_Lz6KbSFK0VcEVxGfO6PpSCdhch%2BfYwVovw%40mail.gmail.com

```
Hi, my initial motivation for this patch was to add NTLM proxy
authentication so I could 'git clone' from inside my employers
network, but apart from doing that, I also added two more features,
so, this patch adds the following improvements to the http proxy
support:

- Support NTLM proxy authentication (as well as other authentication
methods) by setting CURLOPT_PROXYAUTH[1] to CURLAUTH_ANY.

- Look up environment vars http_proxy and HTTP_PROXY in case git
http.proxy config option is not set. This supports system wide proxy
support in terminals.

- Support proxy urls with username but without a password, in which
case we interactively ask for the password (as it's already done in
http auth code). This makes possible to not have the password written
down in git config files or in env vars.

Thanks!

[1] http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXYAUTH


--- http.c	2012-01-19 01:19:22.000000000 +0100
+++ http.mod2.c	2012-02-22 14:44:11.727773038 +0100
@@ -299,8 +299,54 @@
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
 
-	if (curl_http_proxy)
-		curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+	if (!curl_http_proxy) {
+		const char *env_proxy;
+		env_proxy = getenv("HTTP_PROXY");
+		if (!env_proxy) {
+			env_proxy = getenv("http_proxy");
+		}
+		if (env_proxy) {
+			curl_http_proxy = xstrdup(env_proxy);
+		}
+	}
+	if (curl_http_proxy) {
+		char *at, *colon, *proxyuser;
+		const char *cp;
+		cp = strstr(curl_http_proxy, "://");
+		if (cp == NULL) {
+			cp = curl_http_proxy;
+		} else {
+			cp += 3;
+		}
+		at = strchr(cp, '@');
+		colon = strchr(cp, ':');
+		if (at && (!colon || at < colon)) {
+			/* proxy string has username but no password, ask for password */
+			char *ask_str, *proxyuser, *proxypass;
+			int len;
+			struct strbuf pbuf = STRBUF_INIT;
+			len = at - cp;
+			proxyuser = xmalloc(len + 1);
+			memcpy(proxyuser, cp, len);
+			proxyuser[len] = '\0';
+			
+			strbuf_addf(&pbuf, "Enter password for proxy %s...", at+1);
+			ask_str = strbuf_detach(&pbuf, NULL);
+			proxypass = xstrdup(git_getpass(ask_str));
+			
+			strbuf_insert(&pbuf, 0, curl_http_proxy, cp - curl_http_proxy);
+			strbuf_addf(&pbuf, "%s:%s", proxyuser, proxypass);
+			strbuf_add(&pbuf, at, strlen(at));
+			curl_easy_setopt(result, CURLOPT_PROXY, strbuf_detach(&pbuf, NULL));
+			
+			free(ask_str);
+			free(proxyuser);
+			free(proxypass);
+		} else {
+			curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+		}
+		curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+	}
 
 	return result;
 }

```

## Matthieu Moy, 2012-02-22 14:13

Subject: Re: [PATCH] Improve http proxy support
Message-ID: <vpqd397x8fc.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqd397x8fc.fsf%40bauges.imag.fr
In-Reply-To: <CAAUd640GaLz4TGs_Lz6KbSFK0VcEVxGfO6PpSCdhch+fYwVovw@mail.gmail.com>

```
Nelson Benítez León <nbenitezl@gmail.com> writes:

> Hi, my initial motivation for this patch was to add NTLM proxy
> authentication [...]

That sounds interesting, but please read Documentation/SubmittingPatches
in Git's tree. The formatting of your email is wrong (giving more work
for your maintainer) and you need to sign-off your patch to allow your
code to be legally included.

Thanks,

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Thomas Rast, 2012-02-22 16:43

Subject: Re: [PATCH] Improve http proxy support
Message-ID: <87fwe2x1hu.fsf@thomas.inf.ethz.ch>
URL: https://gitlist.dev/e/87fwe2x1hu.fsf%40thomas.inf.ethz.ch
In-Reply-To: <vpqd397x8fc.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Nelson Benítez León <nbenitezl@gmail.com> writes:
>
>> Hi, my initial motivation for this patch was to add NTLM proxy
>> authentication [...]
>
> That sounds interesting, but please read Documentation/SubmittingPatches
> in Git's tree. The formatting of your email is wrong (giving more work
> for your maintainer) and you need to sign-off your patch to allow your
> code to be legally included.

Judging from the message, it also conflates three changes into one
patch.  Don't do that.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```

## Nelson Benítez León, 2012-02-23 12:20

Subject: Re: [PATCH] Improve http proxy support
Message-ID: <CAAUd643RHOrhm+gfW5UeXfjcG0Xr+q0nxzAVqYsh8VxhhP_m1g@mail.gmail.com>
URL: https://gitlist.dev/e/CAAUd643RHOrhm%2BgfW5UeXfjcG0Xr%2Bq0nxzAVqYsh8VxhhP_m1g%40mail.gmail.com
In-Reply-To: <vpqd397x8fc.fsf@bauges.imag.fr>

```
El día 22 de febrero de 2012 15:13, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> escribió:
> Nelson Benítez León <nbenitezl@gmail.com> writes:
>
>> Hi, my initial motivation for this patch was to add NTLM proxy
>> authentication [...]
>
> That sounds interesting, but please read Documentation/SubmittingPatches
> in Git's tree. The formatting of your email is wrong (giving more work
> for your maintainer) and you need to sign-off your patch to allow your
> code to be legally included.

Thank you for the advice, I read README file (couldn't find a HACKING
one) and the git website, and neither of those had a reference to
SubmittingPatches..

```

## Matthieu Moy, 2012-02-23 12:52

Subject: [PATCH] README: point to Documentation/SubmittingPatches
Message-ID: <1330001526-23772-1-git-send-email-Matthieu.Moy@imag.fr>
URL: https://gitlist.dev/e/1330001526-23772-1-git-send-email-Matthieu.Moy%40imag.fr
In-Reply-To: <CAAUd643RHOrhm+gfW5UeXfjcG0Xr+q0nxzAVqYsh8VxhhP_m1g@mail.gmail.com>

```
It was indeed not obvious for new contributors to find this document in
the source tree, since there were no reference to it outside the
Documentation/ directory.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
> Thank you for the advice, I read README file (couldn't find a HACKING
> one) and the git website, and neither of those had a reference to
> SubmittingPatches..

Indeed. As a bonnus, here's a submission that should match the
guidelines (above --- is the commit message, and here is the place for
free comments).

 README |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/README b/README
index 67cfeb2..d2690ec 100644
--- a/README
+++ b/README
@@ -42,10 +42,12 @@ including full documentation and Git related tools.
 
 The user discussion and development of Git take place on the Git
 mailing list -- everyone is welcome to post bug reports, feature
-requests, comments and patches to git@vger.kernel.org. To subscribe
-to the list, send an email with just "subscribe git" in the body to
-majordomo@vger.kernel.org. The mailing list archives are available at
-http://marc.theaimsgroup.com/?l=git and other archival sites.
+requests, comments and patches to git@vger.kernel.org (read
+Documentation/SubmittingPatches for instructions on patch submission).
+To subscribe to the list, send an email with just "subscribe git" in
+the body to majordomo@vger.kernel.org. The mailing list archives are
+available at http://marc.theaimsgroup.com/?l=git and other archival
+sites.
 
 The messages titled "A note from the maintainer", "What's in
 git.git (stable)" and "What's cooking in git.git (topics)" and
-- 
1.7.9.111.gf3fb0.dirty

```
