http: add http.version option to select http protocol version
diff mbox series

Message ID 98295da2b5295795414eaf85a40b9ae62b1b2dca.1544482124.git.silvio.fricke@gmail.com
State New
Headers show
Series
  • http: add http.version option to select http protocol version
Related show

Commit Message

S. Fricke Dec. 10, 2018, 10:49 p.m. UTC
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@gmail.com>
---

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(+)

Comments

Eric Sunshine Dec. 10, 2018, 11:47 p.m. UTC | #1
On Mon, Dec 10, 2018 at 5:50 PM Silvio Fricke <silvio.fricke@gmail.com> wrote:
> 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@gmail.com>

This looks very similar to [1] which is already in Junio's "next"
branch (although not yet in a released version of Git).

[1]: https://public-inbox.org/git/71f8b71b346f132d0dc9a23c9a7f2ca2cb91966f.1541735051.git.gitgitgadget@gmail.com/
S. Fricke Dec. 11, 2018, 6:56 a.m. UTC | #2
Hi Eric,


> On Mon, Dec 10, 2018 at 5:50 PM Silvio Fricke <silvio.fricke@gmail.com> wrote:
> > HTTP has several protocol versions. By default, libcurl is using HTTP/2

[...]

> This looks very similar to [1] which is already in Junio's "next"
> branch (although not yet in a released version of Git).
> 
> [1]: https://public-inbox.org/git/71f8b71b346f132d0dc9a23c9a7f2ca2cb91966f.1541735051.git.gitgitgadget@gmail.com/

Thanks for the pointer. Looks like I need todo more search than to develop
solutions. ^^

The 8th patch version from charlieio@outlook.com looks better than my
implementation.

Thanks and bye,
Silvio
Johannes Schindelin Dec. 11, 2018, 12:40 p.m. UTC | #3
Hi Eric,

On Mon, 10 Dec 2018, Eric Sunshine wrote:

> On Mon, Dec 10, 2018 at 5:50 PM Silvio Fricke <silvio.fricke@gmail.com> wrote:
> > 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.

Please note that this has been addressed for NTLM in
https://github.com/curl/curl/pull/3345 and the gssapi problem is probably
worked around by https://github.com/curl/curl/pull/3349.

Both patches were backported to the cURL version included in Git for
Windows v2.20.0.

> > Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
> 
> This looks very similar to [1] which is already in Junio's "next"
> branch (although not yet in a released version of Git).

Small correction: it is in Git *for Windows* v2.20.0, so in a manner of
speaking it *is* in a released version of Git.

The reason: even if we included the NTLM/Kerberos patches in Git for
Windows, there might be other scenarios where neither of those patches
catch.

Ciao,
Johannes

> [1]: https://public-inbox.org/git/71f8b71b346f132d0dc9a23c9a7f2ca2cb91966f.1541735051.git.gitgitgadget@gmail.com/
>

Patch
diff mbox series

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;