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

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.