threads / patch / 24657

v2Allow HTTP user agent string to be modified.

Subject: [PATCH v2] Allow HTTP user agent string to be modified.

## tl;dr

14 messages between Aug 7, 2010 and Aug 12, 2010. Diffs are folded; open one to read it.

replies: 13people: 5as markdown or json

Spencer E. Olson· Aug 7, 2010, 03:34 UTC · lore

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(-)
Show changes to 2 files +19 −1

Documentation/config.txt, http.c

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
Ævar Arnfjörð Bjarmason· Aug 7, 2010, 08:34 UTC · re: Spencer E. Olson · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

On Sat, Aug 7, 2010 at 03:34, Spencer E. Olson <olsonse@umich.edu> wrote:
Show 5 quoted lines
> -       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);
Spencer E. Olson· Aug 7, 2010, 17:29 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

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:
Show 16 quoted lines
> 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);
> 
> 
Ævar Arnfjörð Bjarmason· Aug 7, 2010, 17:39 UTC · re: Spencer E. Olson · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

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.
Tay Ray Chuan· Aug 8, 2010, 02:49 UTC · re: Spencer E. Olson · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

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
Tay Ray Chuan· Aug 8, 2010, 02:51 UTC · re: Spencer E. Olson · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

Hi,
On Sat, Aug 7, 2010 at 11:34 AM, Spencer E. Olson <olsonse@umich.edu> wrote:
Show 6 quoted lines
>[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.
Show 10 quoted lines
>[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
Spencer E. Olson· Aug 8, 2010, 03:57 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Allow HTTP user agent string to be modified.

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...

Show 18 quoted lines
> 
> >[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.
Spencer E. Olson· Aug 11, 2010, 05:24 UTC · re: Tay Ray Chuan · lore

[PATCH v3] Allow HTTP user agent string to be modified.

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(-)
Show changes to 2 files +17 −1

Documentation/config.txt, http.c

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
Tay Ray Chuan· Aug 11, 2010, 08:04 UTC · re: Spencer E. Olson · lore

Re: [PATCH v3] Allow HTTP user agent string to be modified.

On Wed, Aug 11, 2010 at 1:24 PM, Spencer E. Olson <olsonse@umich.edu> wrote:
Show 12 quoted lines
> 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
Junio C Hamano· Aug 11, 2010, 20:08 UTC · re: Spencer E. Olson · lore

Re: [PATCH v3] Allow HTTP user agent string to be modified.

"Spencer E. Olson" <olsonse@umich.edu> writes:
Show 29 quoted lines
> 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 ")".
Show 8 quoted lines
>  
>  	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...

Spencer E. Olson· Aug 11, 2010, 20:32 UTC · re: Junio C Hamano · lore

[PATCH v4] Allow HTTP user agent string to be modified.

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(-)
Show changes to 3 files +18 −2

Documentation/config.txt, Makefile, http.c

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
Jacob Helwig· Aug 11, 2010, 20:35 UTC · re: Spencer E. Olson · lore

Re: [PATCH v4] Allow HTTP user agent string to be modified.

On Wed, Aug 11, 2010 at 13:32, Spencer E. Olson <olsonse@umich.edu> wrote:
Show 5 quoted lines
> 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.

Show 103 quoted lines
> 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
>
Spencer E. Olson· Aug 11, 2010, 20:40 UTC · re: Jacob Helwig · lore

[PATCH v5] Allow HTTP user agent string to be modified.

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(-)
Show changes to 3 files +18 −2

Documentation/config.txt, Makefile, http.c

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

← back to recent threads