threads / patch / 29692

patchImprove http proxy support

Subject: [PATCH] Improve http proxy support

## tl;dr

5 messages between Feb 22, 2012 and Feb 23, 2012. Diffs are folded; open one to read it.

replies: 4people: 4as markdown or json

Nelson Benítez León· Feb 22, 2012, 14:04 UTC · lore

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

Show changes to diff +48 −2
@@ -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· Feb 22, 2012, 14:13 UTC · re: Nelson Benítez León · lore

Re: [PATCH] Improve http proxy support

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· Feb 22, 2012, 16:43 UTC · re: Matthieu Moy · lore

Re: [PATCH] Improve http proxy support

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 9 quoted lines
> 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· Feb 23, 2012, 12:20 UTC · re: Matthieu Moy · lore

Re: [PATCH] Improve http proxy support

El día 22 de febrero de 2012 15:13, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> escribió:

Show 9 quoted lines
> 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· Feb 23, 2012, 12:52 UTC · re: Nelson Benítez León · lore

[PATCH] README: point to Documentation/SubmittingPatches

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(-)
Show changes to README +6 −4
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

← back to recent threads