diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-01-04 21:33:32 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-01-04 21:33:32 (GMT) |
commit | 13d991929810ebfdf6b75d91cdc72561213d548a (patch) | |
tree | 90488d70c3d63f2b80788fbb049d082260ba4c76 | |
parent | ac193e0e0aa5e93263b82777219167c83c316b7e (diff) | |
parent | d73019feb44b9cb89d9967fb36eae809e8146ace (diff) | |
download | git-13d991929810ebfdf6b75d91cdc72561213d548a.zip git-13d991929810ebfdf6b75d91cdc72561213d548a.tar.gz git-13d991929810ebfdf6b75d91cdc72561213d548a.tar.bz2 |
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
-rw-r--r-- | Documentation/config/http.txt | 9 | ||||
-rw-r--r-- | http.c | 39 |
2 files changed, 48 insertions, 0 deletions
diff --git a/Documentation/config/http.txt b/Documentation/config/http.txt index a56d848..5a32f5b 100644 --- a/Documentation/config/http.txt +++ b/Documentation/config/http.txt @@ -68,6 +68,15 @@ http.saveCookies:: If set, store cookies received during requests to the file specified by http.cookieFile. Has no effect if http.cookieFile is unset. +http.version:: + Use the specified HTTP protocol version when communicating with a server. + If you want to force the default. The available and default version depend + on libcurl. Actually the possible values of + this option are: + + - HTTP/2 + - HTTP/1.1 + http.sslVersion:: The SSL version to use when negotiating an SSL connection, if you want to force the default. The available and default version @@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE]; static int curl_ssl_verify = -1; static int curl_ssl_try; +static const char *curl_http_version = NULL; static const char *ssl_cert; static const char *ssl_cipherlist; static const char *ssl_version; @@ -284,6 +285,9 @@ static void process_curl_messages(void) static int http_options(const char *var, const char *value, void *cb) { + if (!strcmp("http.version", var)) { + return git_config_string(&curl_http_version, var, value); + } if (!strcmp("http.sslverify", var)) { curl_ssl_verify = git_config_bool(var, value); return 0; @@ -789,6 +793,31 @@ static long get_curl_allowed_protocols(int from_user) } #endif +#if LIBCURL_VERSION_NUM >=0x072f00 +static int get_curl_http_version_opt(const char *version_string, long *opt) +{ + int i; + static struct { + const char *name; + long opt_token; + } choice[] = { + { "HTTP/1.1", CURL_HTTP_VERSION_1_1 }, + { "HTTP/2", CURL_HTTP_VERSION_2 } + }; + + for (i = 0; i < ARRAY_SIZE(choice); i++) { + if (!strcmp(version_string, choice[i].name)) { + *opt = choice[i].opt_token; + return 0; + } + } + + warning("unknown value given to http.version: '%s'", version_string); + return -1; /* not found */ +} + +#endif + static CURL *get_curl_handle(void) { CURL *result = curl_easy_init(); @@ -806,6 +835,16 @@ static CURL *get_curl_handle(void) curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2); } +#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0 + if (curl_http_version) { + long opt; + if (!get_curl_http_version_opt(curl_http_version, &opt)) { + /* Set request use http version */ + curl_easy_setopt(result, CURLOPT_HTTP_VERSION, opt); + } + } +#endif + #if LIBCURL_VERSION_NUM >= 0x070907 curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); #endif |