提交 b1d1058c 编写于 作者: S Spencer E. Olson 提交者: Junio C Hamano

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: NSpencer E. Olson <olsonse@umich.edu>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 64fdc08d
...@@ -1243,6 +1243,15 @@ http.noEPSV:: ...@@ -1243,6 +1243,15 @@ http.noEPSV::
support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV' support EPSV mode. Can be overridden by the 'GIT_CURL_FTP_NO_EPSV'
environment variable. Default is false (curl will use 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:: i18n.commitEncoding::
Character encoding the commit messages are stored in; git itself Character encoding the commit messages are stored in; git itself
does not care per se, but this information is necessary e.g. when does not care per se, but this information is necessary e.g. when
......
...@@ -1872,7 +1872,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ ...@@ -1872,7 +1872,7 @@ builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' 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 ifdef NO_EXPAT
http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
......
...@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1; ...@@ -41,6 +41,7 @@ static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv; static int curl_ftp_no_epsv;
static const char *curl_http_proxy; static const char *curl_http_proxy;
static char *user_name, *user_pass; static char *user_name, *user_pass;
static const char *user_agent;
#if LIBCURL_VERSION_NUM >= 0x071700 #if LIBCURL_VERSION_NUM >= 0x071700
/* Use CURLOPT_KEYPASSWD as is */ /* Use CURLOPT_KEYPASSWD as is */
...@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb) ...@@ -196,6 +197,9 @@ static int http_options(const char *var, const char *value, void *cb)
return 0; return 0;
} }
if (!strcmp("http.useragent", var))
return git_config_string(&user_agent, var, value);
/* Fall back on the default ones */ /* Fall back on the default ones */
return git_default_config(var, value, cb); return git_default_config(var, value, cb);
} }
...@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void) ...@@ -279,7 +283,8 @@ static CURL *get_curl_handle(void)
if (getenv("GIT_CURL_VERBOSE")) if (getenv("GIT_CURL_VERBOSE"))
curl_easy_setopt(result, CURLOPT_VERBOSE, 1); 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) if (curl_ftp_no_epsv)
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0); curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
...@@ -380,6 +385,8 @@ void http_init(struct remote *remote) ...@@ -380,6 +385,8 @@ void http_init(struct remote *remote)
#endif #endif
set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO"); 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"); low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
if (low_speed_limit != NULL) if (low_speed_limit != NULL)
curl_low_speed_limit = strtol(low_speed_limit, NULL, 10); curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册