Skip to content

Commit b1d1058

Browse files
olsonsegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 64fdc08 commit b1d1058

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Documentation/config.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,15 @@ http.noEPSV::
12431243
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
12441244
environment variable. Default is false (curl will use EPSV).
12451245

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+
12461255
i18n.commitEncoding::
12471256
Character encoding the commit messages are stored in; git itself
12481257
does not care per se, but this information is necessary e.g. when

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
18721872

18731873
config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
18741874

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)"'
18761876

18771877
ifdef NO_EXPAT
18781878
http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT

http.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
4141
static int curl_ftp_no_epsv;
4242
static const char *curl_http_proxy;
4343
static char *user_name, *user_pass;
44+
static const char *user_agent;
4445

4546
#if LIBCURL_VERSION_NUM >= 0x071700
4647
/* Use CURLOPT_KEYPASSWD as is */
@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
196197
return 0;
197198
}
198199

200+
if (!strcmp("http.useragent", var))
201+
return git_config_string(&user_agent, var, value);
202+
199203
/* Fall back on the default ones */
200204
return git_default_config(var, value, cb);
201205
}
@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
279283
if (getenv("GIT_CURL_VERBOSE"))
280284
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
281285

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);
283288

284289
if (curl_ftp_no_epsv)
285290
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
380385
#endif
381386
set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
382387

388+
set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
389+
383390
low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
384391
if (low_speed_limit != NULL)
385392
curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);

0 commit comments

Comments
 (0)