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

Re: [PATCH 1/6] http: try http_proxy env var when http.proxy config option is not set

From
Jeff King <peff@peff.net>
Date
May 4, 2012, 07:08 UTC
Message-ID
<20120504070802.GA21895@sigill.intra.peff.net>
In-Reply-To
<4FA2B4D3.90809@seap.minhap.es>
On Thu, May 03, 2012 at 06:39:47PM +0200, Nelson Benitez Leon wrote:
Show 17 quoted lines
> +static const char *read_prot_proxy_env(const char *protocol)
> +{
> +	const char *env_proxy;
> +	struct strbuf var = STRBUF_INIT;
> +
> +	strbuf_addf(&var, "%s_proxy", protocol);
> +	env_proxy = getenv(var.buf);
> +	if (!env_proxy && strcmp("http_proxy", var.buf)) {
> +		char *p;
> +		for (p = var.buf; *p; p++)
> +			*p = toupper(*p);
> +		env_proxy = getenv(var.buf);
> +	}
> +	strbuf_release(&var);
> +	
> +	return env_proxy;
> +}
Thanks, this is way more readable than the previous iteration.
Show 12 quoted lines
> +static int host_allowed_by_noproxy_env (const char *host)
> +{
> +	const char *no_proxy = getenv("no_proxy");
> +	if (!no_proxy)
> +		no_proxy = getenv("NO_PROXY");
> +	if (!no_proxy ||
> +	    (strcmp("*", no_proxy) &&
> +	     !strstr(no_proxy, host)))
> +		return 1;
> +	
> +	return 0;
> +}

This simplified parsing misses a lot of corner cases. Three I can see right off the bat:

  1. If your NO_PROXY is "no-proxy.com", and your host is
     "proxy.com", your code will consider that a match, but curl does
     not.
  2. If your NO_PROXY contains "no-proxy.com", but your host is
     "www.no-proxy.com", curl will consider that a match, but your code
     does not.
  3. If your NO_PROXY contains "no-proxy.com", but your host is
     "no-proxy.com:80", curl will consider that a match, but your code
     does not.

I don't see any way around it besides implementing curl's full tokenizing and matching algorithm, which is about a page of code. I'd really prefer not to re-implement bits of curl (especially because they may change later), but AFAIK there is no way to ask curl "is there a proxy configured, and if so, what is it?".

The rest of this patch looks OK to me, though.
-Peff
Previous: Junio C HamanoNext: Daniel Stenberg
Message 3 of 9 in “http: try http_proxy env var when http.proxy config option is not set”
  1. 1/6 http: try http_proxy env var when http.proxy config option is not setNelson Benitez Leon, May 3, 2012
  2. Junio C HamanoMay 3, 2012
  3. Jeff KingMay 4, 2012
  4. Daniel StenbergMay 4, 2012
  5. Jeff KingMay 4, 2012
  6. Daniel StenbergMay 4, 2012
  7. Junio C HamanoMay 4, 2012
  8. Jeff KingMay 4, 2012
  9. Junio C HamanoMay 4, 2012

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.