Skip to content

Commit dfdb1e4

Browse files
committed
Merge branch 'so/http-user-agent'
* so/http-user-agent: Allow HTTP user agent string to be modified.
2 parents e40b34b + b1d1058 commit dfdb1e4

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
@@ -1248,6 +1248,15 @@ http.noEPSV::
12481248
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
12491249
environment variable. Default is false (curl will use EPSV).
12501250

1251+
http.useragent::
1252+
The HTTP USER_AGENT string presented to an HTTP server. The default
1253+
value represents the version of the client git such as git/1.7.1.
1254+
This option allows you to override this value to a more common value
1255+
such as Mozilla/4.0. This may be necessary, for instance, if
1256+
connecting through a firewall that restricts HTTP connections to a set
1257+
of common USER_AGENT strings (but not including those like git/1.7.1).
1258+
Can be overridden by the 'GIT_HTTP_USER_AGENT' environment variable.
1259+
12511260
i18n.commitEncoding::
12521261
Character encoding the commit messages are stored in; git itself
12531262
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
@@ -1873,7 +1873,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
18731873

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

1876-
http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
1876+
http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
18771877

18781878
ifdef NO_EXPAT
18791879
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)