Skip to content

Commit 13d9919

Browse files
committed
Merge branch 'fc/http-version'
The "http.version" configuration variable can be used with recent enough cURL library to force the version of HTTP used to talk when fetching and pushing. * fc/http-version: http: add support selecting http version
2 parents ac193e0 + d73019f commit 13d9919

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Documentation/config/http.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ http.saveCookies::
6868
If set, store cookies received during requests to the file specified by
6969
http.cookieFile. Has no effect if http.cookieFile is unset.
7070

71+
http.version::
72+
Use the specified HTTP protocol version when communicating with a server.
73+
If you want to force the default. The available and default version depend
74+
on libcurl. Actually the possible values of
75+
this option are:
76+
77+
- HTTP/2
78+
- HTTP/1.1
79+
7180
http.sslVersion::
7281
The SSL version to use when negotiating an SSL connection, if you
7382
want to force the default. The available and default version

http.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
4848

4949
static int curl_ssl_verify = -1;
5050
static int curl_ssl_try;
51+
static const char *curl_http_version = NULL;
5152
static const char *ssl_cert;
5253
static const char *ssl_cipherlist;
5354
static const char *ssl_version;
@@ -284,6 +285,9 @@ static void process_curl_messages(void)
284285

285286
static int http_options(const char *var, const char *value, void *cb)
286287
{
288+
if (!strcmp("http.version", var)) {
289+
return git_config_string(&curl_http_version, var, value);
290+
}
287291
if (!strcmp("http.sslverify", var)) {
288292
curl_ssl_verify = git_config_bool(var, value);
289293
return 0;
@@ -789,6 +793,31 @@ static long get_curl_allowed_protocols(int from_user)
789793
}
790794
#endif
791795

796+
#if LIBCURL_VERSION_NUM >=0x072f00
797+
static int get_curl_http_version_opt(const char *version_string, long *opt)
798+
{
799+
int i;
800+
static struct {
801+
const char *name;
802+
long opt_token;
803+
} choice[] = {
804+
{ "HTTP/1.1", CURL_HTTP_VERSION_1_1 },
805+
{ "HTTP/2", CURL_HTTP_VERSION_2 }
806+
};
807+
808+
for (i = 0; i < ARRAY_SIZE(choice); i++) {
809+
if (!strcmp(version_string, choice[i].name)) {
810+
*opt = choice[i].opt_token;
811+
return 0;
812+
}
813+
}
814+
815+
warning("unknown value given to http.version: '%s'", version_string);
816+
return -1; /* not found */
817+
}
818+
819+
#endif
820+
792821
static CURL *get_curl_handle(void)
793822
{
794823
CURL *result = curl_easy_init();
@@ -806,6 +835,16 @@ static CURL *get_curl_handle(void)
806835
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
807836
}
808837

838+
#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
839+
if (curl_http_version) {
840+
long opt;
841+
if (!get_curl_http_version_opt(curl_http_version, &opt)) {
842+
/* Set request use http version */
843+
curl_easy_setopt(result, CURLOPT_HTTP_VERSION, opt);
844+
}
845+
}
846+
#endif
847+
809848
#if LIBCURL_VERSION_NUM >= 0x070907
810849
curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
811850
#endif

0 commit comments

Comments
 (0)