http: fix http_proxy specified without protocol part
PATCH 3/6 http: fix http_proxy specified without protocol part
An earlier patch broke http_proxy specified as <host>:<port> by abusing credential_from_url(). Teach the function to parse that format, but the caller needs to be updated to handle the case where there is no protocol in the parse result.
Also allow keyring implementations to differentiate authentication material meant for http proxies and http destinations by using a different token "http-proxy" to consult them for the former.
--- credential.c | 12 ++++++++---- http.c | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-)
credential.c +8 -4
@@ -324,11 +324,15 @@ void credential_from_url(struct credential *c, const char *url)* (1) proto://<host>/... * (2) proto://<user>@<host>/... * (3) proto://<user>:<pass>@<host>/... +* or "proto://"-less variants of the above. They are not technically +* URLs, but the caller may have some context-specific knowledge about +* what protocol is in use. */ proto_end =strstr (url,"://" ); -if (!proto_end) -return ; - cp = proto_end +3 ; +if (proto_end) + cp = proto_end +3 ; +else + cp = url; at =strchr (cp,'@' ); colon =strchr (cp,':' ); slash =strchrnul (cp,'/' );
@@ -348,7 +352,7 @@ void credential_from_url(struct credential *c, const char *url) host = at +1 ; } -if (proto_end - url >0 ) +if (proto_end && proto_end != url) c->protocol =xmemdupz (url, proto_end - url);if (slash - host >0 ) c->host =url_decode_mem (host, slash - host);
http.c +8 -5
@@ -366,17 +366,20 @@ static CURL *get_curl_handle(const char *url) }if (curl_http_proxy) { -struct strbuf proxyhost =STRBUF_INIT ; - -if (!proxy_auth.host)/* check to parse only once */ +if (!proxy_auth.host) {credential_from_url (&proxy_auth, curl_http_proxy); +if (!proxy_auth.protocol || + !strcmp (proxy_auth.protocol,"http" )) { +free (proxy_auth.protocol); + proxy_auth.protocol =xstrdup ("http-proxy" ); + } + }if (http_proactive_auth && proxy_auth.username && !proxy_auth.password)/* proxy string has username but no password, ask for password */ credential_fill (&proxy_auth); -strbuf_addf (&proxyhost,"%s://%s" , proxy_auth.protocol, proxy_auth.host); -curl_easy_setopt (result,CURLOPT_PROXY ,strbuf_detach (&proxyhost,NULL )); +curl_easy_setopt (result,CURLOPT_PROXY , curl_http_proxy);curl_easy_setopt (result,CURLOPT_PROXYAUTH ,CURLAUTH_ANY );set_proxy_auth (result); }
Signature · 1 line
1.7.7.6
Quoted 10 lines · Nelson Benitez Leon
An earlier patch broke
http_proxyspecified as <host>:<port> by abusingcredential_from_url(). Teach the function to parse that format, but the caller needs to be updated to handle the case where there is no protocol in the parse result.Also allow keyring implementations to differentiate authentication material meant for http proxies and http destinations by using a different token "http-proxy" to consult them for the former.
Signed-off-by Junio C Hamano <[email protected]>
Should this be:
From: Junio C Hamano <[email protected]>
?
Also, any time we read "an earlier patch broke..." and that earlier patch is in this series, I have to wonder why the patches are not simply reordered. Shouldn't the first half of this one come first, and just explain the rationale as "teach credential_from_url to handle protocol-less URLs, since those are used for proxy specifications, which we will need to parse in a later patch".
Quoted 9 lines
http.c +0
-1@@ -366,17 +366,20 @@ static CURL *get_curl_handle(const char *url) }if (curl_http_proxy) { -struct strbuf proxyhost =STRBUF_INIT ;
http.c static CURL *get_curl_handle(const char *url) · line 376
Quoted 10 lines
http.c +7
-2- -if (!proxy_auth.host)/* check to parse only once */ +if (!proxy_auth.host) {credential_from_url (&proxy_auth, curl_http_proxy); +if (!proxy_auth.protocol || + !strcmp (proxy_auth.protocol,"http" )) { +free (proxy_auth.protocol); + proxy_auth.protocol =xstrdup ("http-proxy" ); + } + }
And then this hunk would just get squashed in in the first place.
http.c static CURL *get_curl_handle(const char *url) · line 382
Quoted 7 lines
http.c +1
-2if (http_proactive_auth && proxy_auth.username && !proxy_auth.password)/* proxy string has username but no password, ask for password */ credential_fill (&proxy_auth); -strbuf_addf (&proxyhost,"%s://%s" , proxy_auth.protocol, proxy_auth.host); -curl_easy_setopt (result,CURLOPT_PROXY ,strbuf_detach (&proxyhost,NULL )); +curl_easy_setopt (result,CURLOPT_PROXY , curl_http_proxy);
And this too, which gets rid of my complaints about the previous patch.
-Peff