All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Allow HTTP user agent string to be modified.
@ 2010-08-07  3:34 Spencer E. Olson
  2010-08-07  8:34 ` Ævar Arnfjörð Bjarmason
  2010-08-08  2:51 ` Tay Ray Chuan
  0 siblings, 2 replies; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-07  3:34 UTC (permalink / raw)
  To: git
  Cc: Nick Hengeveld, Mark Lodato, Tay Ray Chuan, Shawn O. Pearce,
	Spencer E. Olson

Some firewalls restrict HTTP connections based on the clients user agent.  This
commit provides the user the ability to modify the user agent string via either
a new config option (http.useragent) or by an environment variable
(GIT_USER_AGENT).  Relevant documentation is added to Documentation/config.txt.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
---

Hi all,

This is both a reminder and an update for a patch I sent earlier
(http://article.gmane.org/gmane.comp.version-control.git/151434).
This update includes the documentation for the new http.useragent configure
option and the new GIT_USER_AGENT environement variable.  I hadn't seen any
comments on the earlier version of this patch, so I assume it got lost among the
other list activity.  

 Documentation/config.txt |    9 +++++++++
 http.c                   |   11 ++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f81fb91..826e816 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1243,6 +1243,15 @@ http.noEPSV::
 	support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
 	environment variable. Default is false (curl will use EPSV).
 
+http.useragent::
+	The HTTP USER_AGENT string presented to an HTTP server.  The default
+	value represents the version of the client git such as git/1.7.1.
+	This option allows you to override this value to a more common value
+	such as Mozilla/4.0.  This may be necessary, for instance, if
+	connecting through a firewall that restricts HTTP connections to a set
+	of common USER_AGENT strings (but not including those like git/1.7.1).
+	Can be overridden by the 'GIT_USER_AGENT' environment variable.
+
 i18n.commitEncoding::
 	Character encoding the commit messages are stored in; git itself
 	does not care per se, but this information is necessary e.g. when
diff --git a/http.c b/http.c
index 1320c50..3a17193 100644
--- a/http.c
+++ b/http.c
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
 static char *user_name, *user_pass;
+static const char *user_agent = NULL;
 
 #if LIBCURL_VERSION_NUM >= 0x071700
 /* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (!strcmp("http.useragent", var))
+		return git_config_string(&user_agent, var, value);
+
 	/* Fall back on the default ones */
 	return git_default_config(var, value, cb);
 }
@@ -279,7 +283,10 @@ static CURL *get_curl_handle(void)
 	if (getenv("GIT_CURL_VERBOSE"))
 		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
 
-	curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
+	if (user_agent != NULL)
+		curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
+	else
+		curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
 
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +387,8 @@ void http_init(struct remote *remote)
 #endif
 	set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
 
+	set_from_env(&user_agent, "GIT_USER_AGENT");
+
 	low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
 	if (low_speed_limit != NULL)
 		curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-07  3:34 [PATCH v2] Allow HTTP user agent string to be modified Spencer E. Olson
@ 2010-08-07  8:34 ` Ævar Arnfjörð Bjarmason
  2010-08-07 17:29   ` Spencer E. Olson
  2010-08-08  2:51 ` Tay Ray Chuan
  1 sibling, 1 reply; 14+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-08-07  8:34 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: git, Nick Hengeveld, Mark Lodato, Tay Ray Chuan, Shawn O. Pearce

On Sat, Aug 7, 2010 at 03:34, Spencer E. Olson <olsonse@umich.edu> wrote:

> -       curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> +       if (user_agent != NULL)
> +               curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
> +       else
> +               curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);

Can't you just skip the != NULL?:

       if (user_agent)
               curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
       else
               curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-07  8:34 ` Ævar Arnfjörð Bjarmason
@ 2010-08-07 17:29   ` Spencer E. Olson
  2010-08-07 17:39     ` Ævar Arnfjörð Bjarmason
  2010-08-08  2:49     ` Tay Ray Chuan
  0 siblings, 2 replies; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-07 17:29 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Nick Hengeveld, Mark Lodato, Tay Ray Chuan, Shawn O. Pearce

I would have no problem doing that.  I was just trying to match the
style already present in http.c.  All the other pointer tests in that
function/file are done the same.


On Sat, 2010-08-07 at 08:34 +0000, Ævar Arnfjörð Bjarmason wrote:
> On Sat, Aug 7, 2010 at 03:34, Spencer E. Olson <olsonse@umich.edu> wrote:
> 
> > -       curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> > +       if (user_agent != NULL)
> > +               curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
> > +       else
> > +               curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> 
> Can't you just skip the != NULL?:
> 
>        if (user_agent)
>                curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
>        else
>                curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> 
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-07 17:29   ` Spencer E. Olson
@ 2010-08-07 17:39     ` Ævar Arnfjörð Bjarmason
  2010-08-08  2:49     ` Tay Ray Chuan
  1 sibling, 0 replies; 14+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-08-07 17:39 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: git, Nick Hengeveld, Mark Lodato, Tay Ray Chuan, Shawn O. Pearce

On Sat, Aug 7, 2010 at 17:29, Spencer E. Olson <olsonse@umich.edu> wrote:
> I would have no problem doing that.  I was just trying to match the
> style already present in http.c.  All the other pointer tests in that
> function/file are done the same.

Ah, fair enough. I didn't notice that the rest of http.c already used
that style, nevermind then.

It's best to just keep it consistent, and maybe clean it up in some
later patch, but best not to introduce an inconsistency by using a
different style just for this one.

Your patch looks good.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-07 17:29   ` Spencer E. Olson
  2010-08-07 17:39     ` Ævar Arnfjörð Bjarmason
@ 2010-08-08  2:49     ` Tay Ray Chuan
  1 sibling, 0 replies; 14+ messages in thread
From: Tay Ray Chuan @ 2010-08-08  2:49 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: Ævar Arnfjörð,
	git, Nick Hengeveld, Mark Lodato, Shawn O. Pearce

On Sun, Aug 8, 2010 at 1:29 AM, Spencer E. Olson <olsonse@umich.edu> wrote:
> I would have no problem doing that.  I was just trying to match the
> style already present in http.c.  All the other pointer tests in that
> function/file are done the same.

I wouldn't go so far as to say "all" - there is quite a mish-mash of
check styles there.

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-07  3:34 [PATCH v2] Allow HTTP user agent string to be modified Spencer E. Olson
  2010-08-07  8:34 ` Ævar Arnfjörð Bjarmason
@ 2010-08-08  2:51 ` Tay Ray Chuan
  2010-08-08  3:57   ` Spencer E. Olson
  2010-08-11  5:24   ` [PATCH v3] " Spencer E. Olson
  1 sibling, 2 replies; 14+ messages in thread
From: Tay Ray Chuan @ 2010-08-08  2:51 UTC (permalink / raw)
  To: Spencer E. Olson; +Cc: git, Nick Hengeveld, Mark Lodato, Shawn O. Pearce

Hi,

On Sat, Aug 7, 2010 at 11:34 AM, Spencer E. Olson <olsonse@umich.edu> wrote:
>[snip]
> @@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
>  static int curl_ftp_no_epsv;
>  static const char *curl_http_proxy;
>  static char *user_name, *user_pass;
> +static const char *user_agent = NULL;

This can be skipped, I think.

>[snip]
> @@ -279,7 +283,10 @@ static CURL *get_curl_handle(void)
>        if (getenv("GIT_CURL_VERBOSE"))
>                curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
>
> -       curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> +       if (user_agent != NULL)
> +               curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
> +       else
> +               curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);

Hmm, perhaps

    curl_easy_setopt(result, CURLOPT_USERAGENT,
        user_agent ? user_agent : GIT_USER_AGENT);

to replace the if-else?

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Allow HTTP user agent string to be modified.
  2010-08-08  2:51 ` Tay Ray Chuan
@ 2010-08-08  3:57   ` Spencer E. Olson
  2010-08-11  5:24   ` [PATCH v3] " Spencer E. Olson
  1 sibling, 0 replies; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-08  3:57 UTC (permalink / raw)
  To: Tay Ray Chuan; +Cc: git, Nick Hengeveld, Mark Lodato, Shawn O. Pearce

On Sun, 2010-08-08 at 10:51 +0800, Tay Ray Chuan wrote:

> >  static char *user_name, *user_pass;
> > +static const char *user_agent = NULL;
> 
> This can be skipped, I think.

My only reason for wanting to initialize is because I don't trust all
compilers to follow the standard.  But, since there are so many other
instances of relying on the compiler to zero out static vars in other
places already, I don't have any problem with conforming...


> 
> >[snip]
> > @@ -279,7 +283,10 @@ static CURL *get_curl_handle(void)
> >        if (getenv("GIT_CURL_VERBOSE"))
> >                curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
> >
> > -       curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> > +       if (user_agent != NULL)
> > +               curl_easy_setopt(result, CURLOPT_USERAGENT, user_agent);
> > +       else
> > +               curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> 
> Hmm, perhaps
> 
>     curl_easy_setopt(result, CURLOPT_USERAGENT,
>         user_agent ? user_agent : GIT_USER_AGENT);
> 
> to replace the if-else?

That is perfectly fine with me.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] Allow HTTP user agent string to be modified.
  2010-08-08  2:51 ` Tay Ray Chuan
  2010-08-08  3:57   ` Spencer E. Olson
@ 2010-08-11  5:24   ` Spencer E. Olson
  2010-08-11  8:04     ` Tay Ray Chuan
  2010-08-11 20:08     ` Junio C Hamano
  1 sibling, 2 replies; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-11  5:24 UTC (permalink / raw)
  To: git
  Cc: Tay Ray Chuan, Nick Hengeveld, Mark Lodato, Shawn O. Pearce,
	Spencer E. Olson

Some firewalls restrict HTTP connections based on the clients user agent.  This
commit provides the user the ability to modify the user agent string via either
a new config option (http.useragent) or by an environment variable
(GIT_USER_AGENT).  Relevant documentation is added to Documentation/config.txt.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
---

Hi all,

This is an updated version of this patch including the changes suggested by Ray
Chuan.


 Documentation/config.txt |    9 +++++++++
 http.c                   |    9 ++++++++-
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f81fb91..826e816 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1243,6 +1243,15 @@ http.noEPSV::
 	support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
 	environment variable. Default is false (curl will use EPSV).
 
+http.useragent::
+	The HTTP USER_AGENT string presented to an HTTP server.  The default
+	value represents the version of the client git such as git/1.7.1.
+	This option allows you to override this value to a more common value
+	such as Mozilla/4.0.  This may be necessary, for instance, if
+	connecting through a firewall that restricts HTTP connections to a set
+	of common USER_AGENT strings (but not including those like git/1.7.1).
+	Can be overridden by the 'GIT_USER_AGENT' environment variable.
+
 i18n.commitEncoding::
 	Character encoding the commit messages are stored in; git itself
 	does not care per se, but this information is necessary e.g. when
diff --git a/http.c b/http.c
index 1320c50..b0b6925 100644
--- a/http.c
+++ b/http.c
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
 static char *user_name, *user_pass;
+static const char *user_agent;
 
 #if LIBCURL_VERSION_NUM >= 0x071700
 /* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (!strcmp("http.useragent", var))
+		return git_config_string(&user_agent, var, value);
+
 	/* Fall back on the default ones */
 	return git_default_config(var, value, cb);
 }
@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
 	if (getenv("GIT_CURL_VERBOSE"))
 		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
 
-	curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
+	curl_easy_setopt(result, CURLOPT_USERAGENT,
+		user_agent ? user_agent : GIT_USER_AGENT );
 
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
 #endif
 	set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
 
+	set_from_env(&user_agent, "GIT_USER_AGENT");
+
 	low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
 	if (low_speed_limit != NULL)
 		curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Allow HTTP user agent string to be modified.
  2010-08-11  5:24   ` [PATCH v3] " Spencer E. Olson
@ 2010-08-11  8:04     ` Tay Ray Chuan
  2010-08-11 20:08     ` Junio C Hamano
  1 sibling, 0 replies; 14+ messages in thread
From: Tay Ray Chuan @ 2010-08-11  8:04 UTC (permalink / raw)
  To: Spencer E. Olson; +Cc: git, Nick Hengeveld, Mark Lodato, Shawn O. Pearce

On Wed, Aug 11, 2010 at 1:24 PM, Spencer E. Olson <olsonse@umich.edu> wrote:
> Some firewalls restrict HTTP connections based on the clients user agent.  This
> commit provides the user the ability to modify the user agent string via either
> a new config option (http.useragent) or by an environment variable
> (GIT_USER_AGENT).  Relevant documentation is added to Documentation/config.txt.
>
> Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
> ---
>
> Hi all,
>
> This is an updated version of this patch including the changes suggested by Ray
> Chuan.

  Acked-by: Tay Ray Chuan <rctay89@gmail.com>

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Allow HTTP user agent string to be modified.
  2010-08-11  5:24   ` [PATCH v3] " Spencer E. Olson
  2010-08-11  8:04     ` Tay Ray Chuan
@ 2010-08-11 20:08     ` Junio C Hamano
  2010-08-11 20:32       ` [PATCH v4] " Spencer E. Olson
  1 sibling, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2010-08-11 20:08 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: git, Tay Ray Chuan, Nick Hengeveld, Mark Lodato, Shawn O. Pearce

"Spencer E. Olson" <olsonse@umich.edu> writes:

> diff --git a/http.c b/http.c
> index 1320c50..b0b6925 100644
> --- a/http.c
> +++ b/http.c
> @@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
>  static int curl_ftp_no_epsv;
>  static const char *curl_http_proxy;
>  static char *user_name, *user_pass;
> +static const char *user_agent;
>  
>  #if LIBCURL_VERSION_NUM >= 0x071700
>  /* Use CURLOPT_KEYPASSWD as is */
> @@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
>  		return 0;
>  	}
>  
> +	if (!strcmp("http.useragent", var))
> +		return git_config_string(&user_agent, var, value);
> +
>  	/* Fall back on the default ones */
>  	return git_default_config(var, value, cb);
>  }
> @@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
>  	if (getenv("GIT_CURL_VERBOSE"))
>  		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
>  
> -	curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> +	curl_easy_setopt(result, CURLOPT_USERAGENT,
> +		user_agent ? user_agent : GIT_USER_AGENT );

Excess space before ")".

>  
>  	if (curl_ftp_no_epsv)
>  		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
> @@ -380,6 +385,8 @@ void http_init(struct remote *remote)
>  #endif
>  	set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
>  
> +	set_from_env(&user_agent, "GIT_USER_AGENT");

The name GIT_USER_AGENT may be Ok as an internal token used in our http
implementation, but the environment variable is an end-user facing entity.

Don't we want to say HTTP somewhere, e.g. "GIT_HTTP_USER_AGENT"?

If "User Agent" means the "browser claims to be..." thing to everybody
without much context then I won't worry too much, but MUA is a mail user
agent, and we do use the term in our docs when describing send-email,
so...

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v4] Allow HTTP user agent string to be modified.
  2010-08-11 20:08     ` Junio C Hamano
@ 2010-08-11 20:32       ` Spencer E. Olson
  2010-08-11 20:35         ` Jacob Helwig
  0 siblings, 1 reply; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-11 20:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Tay Ray Chuan, Nick Hengeveld, Mark Lodato,
	Shawn O. Pearce, Spencer E. Olson

Some firewalls restrict HTTP connections based on the clients user agent.  This
commit provides the user the ability to modify the user agent string via either
a new config option (http.useragent) or by an environment variable
(GIT_USER_AGENT).  Relevant documentation is added to Documentation/config.txt.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
---

All,

This includes the changes suggested by Ray Chuan and by Junio Hamano, with one
minor additional change:  This changes the internal -DGIT_USER_AGENT to
-DGIT_HTTP_USER_AGENT.

Since GIT_HTTP_* seems to follow what several of the other HTTP related
environement variables, I agree that using GIT_HTTP_USER_AGENT is better for the
user interface (via env variables) than GIT_USER_AGENT.  I would like to
additionally change the internal token also to GIT_HTTP_USER_AGENT just because
it is clearer for other developers.


 Documentation/config.txt |    9 +++++++++
 Makefile                 |    2 +-
 http.c                   |    9 ++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f81fb91..7253b71 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1243,6 +1243,15 @@ http.noEPSV::
 	support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
 	environment variable. Default is false (curl will use EPSV).
 
+http.useragent::
+	The HTTP USER_AGENT string presented to an HTTP server.  The default
+	value represents the version of the client git such as git/1.7.1.
+	This option allows you to override this value to a more common value
+	such as Mozilla/4.0.  This may be necessary, for instance, if
+	connecting through a firewall that restricts HTTP connections to a set
+	of common USER_AGENT strings (but not including those like git/1.7.1).
+	Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
+
 i18n.commitEncoding::
 	Character encoding the commit messages are stored in; git itself
 	does not care per se, but this information is necessary e.g. when
diff --git a/Makefile b/Makefile
index e151516..f84f4a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1873,7 +1873,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
 
 config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
 
-http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
+http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
 
 ifdef NO_EXPAT
 http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
diff --git a/http.c b/http.c
index 1320c50..0a5011f 100644
--- a/http.c
+++ b/http.c
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
 static char *user_name, *user_pass;
+static const char *user_agent;
 
 #if LIBCURL_VERSION_NUM >= 0x071700
 /* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (!strcmp("http.useragent", var))
+		return git_config_string(&user_agent, var, value);
+
 	/* Fall back on the default ones */
 	return git_default_config(var, value, cb);
 }
@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
 	if (getenv("GIT_CURL_VERBOSE"))
 		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
 
-	curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
+	curl_easy_setopt(result, CURLOPT_USERAGENT,
+		user_agent ? user_agent : GIT_HTTP_USER_AGENT);
 
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
 #endif
 	set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
 
+	set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
+
 	low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
 	if (low_speed_limit != NULL)
 		curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v4] Allow HTTP user agent string to be modified.
  2010-08-11 20:32       ` [PATCH v4] " Spencer E. Olson
@ 2010-08-11 20:35         ` Jacob Helwig
  2010-08-11 20:40           ` [PATCH v5] " Spencer E. Olson
  0 siblings, 1 reply; 14+ messages in thread
From: Jacob Helwig @ 2010-08-11 20:35 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: git, Junio C Hamano, Tay Ray Chuan, Nick Hengeveld, Mark Lodato,
	Shawn O. Pearce

On Wed, Aug 11, 2010 at 13:32, Spencer E. Olson <olsonse@umich.edu> wrote:
> Some firewalls restrict HTTP connections based on the clients user agent.  This
> commit provides the user the ability to modify the user agent string via either
> a new config option (http.useragent) or by an environment variable
> (GIT_USER_AGENT).  Relevant documentation is added to Documentation/config.txt.
>

Missed switching GIT_USER_AGENT to GIT_HTTP_USER_AGENT here, in the
commit message, but that seems like something easily enough fixed when
applying.

> Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
> ---
>
> All,
>
> This includes the changes suggested by Ray Chuan and by Junio Hamano, with one
> minor additional change:  This changes the internal -DGIT_USER_AGENT to
> -DGIT_HTTP_USER_AGENT.
>
> Since GIT_HTTP_* seems to follow what several of the other HTTP related
> environement variables, I agree that using GIT_HTTP_USER_AGENT is better for the
> user interface (via env variables) than GIT_USER_AGENT.  I would like to
> additionally change the internal token also to GIT_HTTP_USER_AGENT just because
> it is clearer for other developers.
>
>
>  Documentation/config.txt |    9 +++++++++
>  Makefile                 |    2 +-
>  http.c                   |    9 ++++++++-
>  3 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index f81fb91..7253b71 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -1243,6 +1243,15 @@ http.noEPSV::
>        support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
>        environment variable. Default is false (curl will use EPSV).
>
> +http.useragent::
> +       The HTTP USER_AGENT string presented to an HTTP server.  The default
> +       value represents the version of the client git such as git/1.7.1.
> +       This option allows you to override this value to a more common value
> +       such as Mozilla/4.0.  This may be necessary, for instance, if
> +       connecting through a firewall that restricts HTTP connections to a set
> +       of common USER_AGENT strings (but not including those like git/1.7.1).
> +       Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
> +
>  i18n.commitEncoding::
>        Character encoding the commit messages are stored in; git itself
>        does not care per se, but this information is necessary e.g. when
> diff --git a/Makefile b/Makefile
> index e151516..f84f4a1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1873,7 +1873,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
>
>  config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
>
> -http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
> +http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
>
>  ifdef NO_EXPAT
>  http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
> diff --git a/http.c b/http.c
> index 1320c50..0a5011f 100644
> --- a/http.c
> +++ b/http.c
> @@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
>  static int curl_ftp_no_epsv;
>  static const char *curl_http_proxy;
>  static char *user_name, *user_pass;
> +static const char *user_agent;
>
>  #if LIBCURL_VERSION_NUM >= 0x071700
>  /* Use CURLOPT_KEYPASSWD as is */
> @@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
>                return 0;
>        }
>
> +       if (!strcmp("http.useragent", var))
> +               return git_config_string(&user_agent, var, value);
> +
>        /* Fall back on the default ones */
>        return git_default_config(var, value, cb);
>  }
> @@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
>        if (getenv("GIT_CURL_VERBOSE"))
>                curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
>
> -       curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
> +       curl_easy_setopt(result, CURLOPT_USERAGENT,
> +               user_agent ? user_agent : GIT_HTTP_USER_AGENT);
>
>        if (curl_ftp_no_epsv)
>                curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
> @@ -380,6 +385,8 @@ void http_init(struct remote *remote)
>  #endif
>        set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
>
> +       set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
> +
>        low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
>        if (low_speed_limit != NULL)
>                curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
> --
> 1.7.0.4
>
> --
> 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
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v5] Allow HTTP user agent string to be modified.
  2010-08-11 20:35         ` Jacob Helwig
@ 2010-08-11 20:40           ` Spencer E. Olson
  2010-08-12 17:23             ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Spencer E. Olson @ 2010-08-11 20:40 UTC (permalink / raw)
  To: git
  Cc: Jacob Helwig, Junio C Hamano, Tay Ray Chuan, Nick Hengeveld,
	Mark Lodato, Shawn O. Pearce, Spencer E. Olson

Some firewalls restrict HTTP connections based on the clients user agent.  This
commit provides the user the ability to modify the user agent string via either
a new config option (http.useragent) or by an environment variable
(GIT_HTTP_USER_AGENT).  Relevant documentation is added to
Documentation/config.txt.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
---

Thanks Jacob.  Here is with the commit message fixed.


 Documentation/config.txt |    9 +++++++++
 Makefile                 |    2 +-
 http.c                   |    9 ++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index f81fb91..7253b71 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1243,6 +1243,15 @@ http.noEPSV::
 	support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
 	environment variable. Default is false (curl will use EPSV).
 
+http.useragent::
+	The HTTP USER_AGENT string presented to an HTTP server.  The default
+	value represents the version of the client git such as git/1.7.1.
+	This option allows you to override this value to a more common value
+	such as Mozilla/4.0.  This may be necessary, for instance, if
+	connecting through a firewall that restricts HTTP connections to a set
+	of common USER_AGENT strings (but not including those like git/1.7.1).
+	Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
+
 i18n.commitEncoding::
 	Character encoding the commit messages are stored in; git itself
 	does not care per se, but this information is necessary e.g. when
diff --git a/Makefile b/Makefile
index e151516..f84f4a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1873,7 +1873,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
 
 config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
 
-http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
+http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
 
 ifdef NO_EXPAT
 http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
diff --git a/http.c b/http.c
index 1320c50..0a5011f 100644
--- a/http.c
+++ b/http.c
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
 static char *user_name, *user_pass;
+static const char *user_agent;
 
 #if LIBCURL_VERSION_NUM >= 0x071700
 /* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	if (!strcmp("http.useragent", var))
+		return git_config_string(&user_agent, var, value);
+
 	/* Fall back on the default ones */
 	return git_default_config(var, value, cb);
 }
@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
 	if (getenv("GIT_CURL_VERBOSE"))
 		curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
 
-	curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
+	curl_easy_setopt(result, CURLOPT_USERAGENT,
+		user_agent ? user_agent : GIT_HTTP_USER_AGENT);
 
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
 #endif
 	set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
 
+	set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
+
 	low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
 	if (low_speed_limit != NULL)
 		curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v5] Allow HTTP user agent string to be modified.
  2010-08-11 20:40           ` [PATCH v5] " Spencer E. Olson
@ 2010-08-12 17:23             ` Junio C Hamano
  0 siblings, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2010-08-12 17:23 UTC (permalink / raw)
  To: Spencer E. Olson
  Cc: git, Jacob Helwig, Tay Ray Chuan, Nick Hengeveld, Mark Lodato,
	Shawn O. Pearce

Looks good; thanks.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-08-12 17:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-07  3:34 [PATCH v2] Allow HTTP user agent string to be modified Spencer E. Olson
2010-08-07  8:34 ` Ævar Arnfjörð Bjarmason
2010-08-07 17:29   ` Spencer E. Olson
2010-08-07 17:39     ` Ævar Arnfjörð Bjarmason
2010-08-08  2:49     ` Tay Ray Chuan
2010-08-08  2:51 ` Tay Ray Chuan
2010-08-08  3:57   ` Spencer E. Olson
2010-08-11  5:24   ` [PATCH v3] " Spencer E. Olson
2010-08-11  8:04     ` Tay Ray Chuan
2010-08-11 20:08     ` Junio C Hamano
2010-08-11 20:32       ` [PATCH v4] " Spencer E. Olson
2010-08-11 20:35         ` Jacob Helwig
2010-08-11 20:40           ` [PATCH v5] " Spencer E. Olson
2010-08-12 17:23             ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.