[PATCH] http: add http.version option to select http protocol version

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HTTP has several protocol versions. By default, libcurl is using HTTP/2
today and check if the remote can use this protocol variant and fall
back to a previous version if not.

Under rare conditions it is needed to switch the used protocol version
to fight again wrongly implemented authorization mechanism like ntlm
with gssapi on remote side.

Signed-off-by: Silvio Fricke <silvio.fricke@xxxxxxxxx>
---

Notes:
    I hit a problem with a libcurl (Namely [this bug]). This bug looks
    like never get fixed and to just-use-git from my commandline I don't want
    compile a own libcurl with disabled gssapi or/and http/2.
    
    [this bug]: https://github.com/curl/curl/issues/876

 Documentation/config/http.txt | 10 ++++++++++
 http.c                        | 23 +++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git Documentation/config/http.txt Documentation/config/http.txt
index a56d848bc0..0d2840696b 100644
--- Documentation/config/http.txt
+++ Documentation/config/http.txt
@@ -68,6 +68,16 @@ 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::
+	If set, use the specific http(s) protocol version.
+	Actually this versions are possible:
+
+	- 2.0 -> HTTP/2
+	- 2   -> HTTP/2
+	- 1.1 -> HTTP/1.1
+	- 1.0 -> HTTP/1.0
+	- 1   -> HTTP/1.0
+
 http.sslVersion::
 	The SSL version to use when negotiating an SSL connection, if you
 	want to force the default.  The available and default version
diff --git http.c http.c
index eacc2a75ef..99cdd327a5 100644
--- http.c
+++ http.c
@@ -83,6 +83,7 @@ static const char *ssl_cainfo;
 static long curl_low_speed_limit = -1;
 static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
+static const char *curl_http_version;
 static const char *curl_http_proxy;
 static const char *http_proxy_authmethod;
 static struct {
@@ -355,6 +356,10 @@ static int http_options(const char *var, const char *value, void *cb)
 		curl_ftp_no_epsv = git_config_bool(var, value);
 		return 0;
 	}
+
+	if (!strcmp("http.version", var))
+		return git_config_string(&curl_http_version, var, value);
+
 	if (!strcmp("http.proxy", var))
 		return git_config_string(&curl_http_proxy, var, value);
 
@@ -926,6 +931,19 @@ static CURL *get_curl_handle(void)
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
 
+	if (curl_http_version) {
+		if (!strcmp(curl_http_version, "2") || !strcmp(curl_http_version, "2.0"))
+			curl_easy_setopt(result, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
+		else if (!strcmp(curl_http_version, "2TLS"))
+			curl_easy_setopt(result, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
+		else if (!strcmp(curl_http_version, "1.1"))
+			curl_easy_setopt(result, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+		else if (!strcmp(curl_http_version, "1.0") || strcmp(curl_http_version, "1"))
+			curl_easy_setopt(result, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+		else
+			warning(_("Use default http(s) protocol"));
+	}
+
 #ifdef CURLOPT_USE_SSL
 	if (curl_ssl_try)
 		curl_easy_setopt(result, CURLOPT_USE_SSL, CURLUSESSL_TRY);
@@ -1169,6 +1187,11 @@ void http_cleanup(void)
 	curl_slist_free_all(no_pragma_header);
 	no_pragma_header = NULL;
 
+	if (curl_http_version) {
+		free((void *)curl_http_version);
+		curl_http_version = NULL;
+	}
+
 	if (curl_http_proxy) {
 		free((void *)curl_http_proxy);
 		curl_http_proxy = NULL;
-- 
2.19.2




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux