http: add support selecting http version
Usually we don't need to set libcurl to choose which version of the HTTP protocol to use to communicate with a server. But different versions of libcurl, the default value is not the same. CURL >= 7.62.0: CURL_HTTP_VERSION_2TLS CURL < 7.62: CURL_HTTP_VERSION_1_1 In order to give users the freedom to control the HTTP version, we need to add a setting to choose which HTTP version to use. Signed-off-by: Force Charlie <charlieio@outlook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Force Charlie committed
Nov 8, 2018 at 19:44 UTC
d73019feb44b9cb89d9967fb36eae809e8146ace
2 files changed
+48
Documentation/config.txt
+9
@@ -1935,6 +1935,15 @@ http.saveCookies::
1935
If set, store cookies received during requests to the file specified by
1936
http.cookieFile. Has no effect if http.cookieFile is unset.
1937
1938
+http.version::
1939
+ Use the specified HTTP protocol version when communicating with a server.
1940
+ If you want to force the default. The available and default version depend
1941
+ on libcurl. Actually the possible values of
1942
+ this option are:
1943
+
1944
+ - HTTP/2
1945
+ - HTTP/1.1
1946
+
1947
http.sslVersion::
1948
The SSL version to use when negotiating an SSL connection, if you
1949
want to force the default. The available and default version
http.c
+39
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
48
49
static int curl_ssl_verify = -1;
50
static int curl_ssl_try;
51
+static const char *curl_http_version = NULL;
52
static const char *ssl_cert;
53
static const char *ssl_cipherlist;
54
static const char *ssl_version;
@@ -284,6 +285,9 @@ static void process_curl_messages(void)
285
286
static int http_options(const char *var, const char *value, void *cb)
287
{
288
+ if (!strcmp("http.version", var)) {
289
+ return git_config_string(&curl_http_version, var, value);
290
+ }
291
if (!strcmp("http.sslverify", var)) {
292
curl_ssl_verify = git_config_bool(var, value);
293
return 0;
@@ -789,6 +793,31 @@ static long get_curl_allowed_protocols(int from_user)
793
}
794
#endif
795
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
+
821
static CURL *get_curl_handle(void)
822
{
823
CURL *result = curl_easy_init();
@@ -806,6 +835,16 @@ static CURL *get_curl_handle(void)
835
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
836
}
837
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
+
848
#if LIBCURL_VERSION_NUM >= 0x070907
849
curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
850
#endif