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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Spencer E. Olson committed
Aug 11, 2010 at 14:40 UTC
b1d1058cc348a985a6209f920fab0db592dc83de
3 files changed
+18
-2
Documentation/config.txt
+9
@@ -1243,6 +1243,15 @@ http.noEPSV::
1243
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
1244
environment variable. Default is false (curl will use EPSV).
1245
1246
+http.useragent::
1247
+ The HTTP USER_AGENT string presented to an HTTP server. The default
1248
+ value represents the version of the client git such as git/1.7.1.
1249
+ This option allows you to override this value to a more common value
1250
+ such as Mozilla/4.0. This may be necessary, for instance, if
1251
+ connecting through a firewall that restricts HTTP connections to a set
1252
+ of common USER_AGENT strings (but not including those like git/1.7.1).
1253
+ Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
1254
+
1255
i18n.commitEncoding::
1256
Character encoding the commit messages are stored in; git itself
1257
does not care per se, but this information is necessary e.g. when
Makefile
+1
-1
@@ -1872,7 +1872,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
1872
1873
config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
1874
1875
-http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
1875
+http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
1876
1877
ifdef NO_EXPAT
1878
http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
http.c
+8
-1
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
41
static int curl_ftp_no_epsv;
42
static const char *curl_http_proxy;
43
static char *user_name, *user_pass;
44
+static const char *user_agent;
45
46
#if LIBCURL_VERSION_NUM >= 0x071700
47
/* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
197
return 0;
198
}
199
200
+ if (!strcmp("http.useragent", var))
201
+ return git_config_string(&user_agent, var, value);
202
+
203
/* Fall back on the default ones */
204
return git_default_config(var, value, cb);
205
}
@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
283
if (getenv("GIT_CURL_VERBOSE"))
284
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
285
282
- curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT);
286
+ curl_easy_setopt(result, CURLOPT_USERAGENT,
287
+ user_agent ? user_agent : GIT_HTTP_USER_AGENT);
288
289
if (curl_ftp_no_epsv)
290
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
385
#endif
386
set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
387
388
+ set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
389
+
390
low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
391
if (low_speed_limit != NULL)
392
curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);