threads / patch / 49777

patchhttp: add support selecting http version

Subject: [PATCH 0/1] http: add support selecting http version

## tl;dr

33 messages between Nov 7, 2018 and Nov 9, 2018. Diffs are folded; open one to read it.

replies: 32people: 6as markdown or json

Force.Charlie-I via GitGitGadget· Nov 7, 2018, 13:33 UTC · lore

Normally, git doesn't need to set curl to select the HTTP version, it works fine without HTTP2. Adding HTTP2 support is a icing on the cake.

When http.version=20 is set, git will attempt to request the server using HTTP2. If the remote server does not support HTTP2, it is no different. Currently bitbucket supports HTTP2 and is available for testing.

example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=20 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (1):
  http: add support selecting http version
 http.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/69
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 7, 2018, 13:33 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH 1/1] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Show changes to http.c +12 −0
diff --git a/http.c b/http.c
index 3dc8c560d6..99cb04faba 100644
--- a/http.c
+++ b/http.c
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
+static int curl_http_version = 11;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -284,6 +285,10 @@ static void process_curl_messages(void)
 
 static int http_options(const char *var, const char *value, void *cb)
 {
+	if (!strcmp("http.version",var)) {
+		curl_http_version=git_config_int(var,value);
+		return 0;
+	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
 		return 0;
@@ -806,6 +811,13 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
+#if LIBCURL_VERSION_NUM >= 0x073100
+	if(curl_http_version == 20){
+		/* CURL Enable HTTP2*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
+     }
+#endif
+
 #if LIBCURL_VERSION_NUM >= 0x070907
 	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 #endif
-- 
gitgitgadget
Junio C Hamano· Nov 8, 2018, 01:48 UTC · re: Force Charlie via GitGitGadget · lore

Re: [PATCH 1/1] http: add support selecting http version

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 16 quoted lines
> From: Force Charlie <charlieio@outlook.com>
>
> Signed-off-by: Force Charlie <charlieio@outlook.com>
> ---
>  http.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/http.c b/http.c
> index 3dc8c560d6..99cb04faba 100644
> --- a/http.c
> +++ b/http.c
> @@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
>  
>  static int curl_ssl_verify = -1;
>  static int curl_ssl_try;
> +static int curl_http_version = 11;

Is there any reason that we need to have this variable's value to be "int"? I _think_ in this patch, the variable is used to choose between the default and "HTTP/2", and I do not think the updated code can choose any other new value that may be supported by an even newer cURL library without further update, i.e. we'd need a variant of "if the configuration asks HTTP/2 then use CURLOPT_HTTP_VERSION with CURL_HTTP_VERSION_2" for the new choice.

So I'd think it would not add much value to force end users use a rather cryptic "20" (vs "11") to choose between "2" and "1.1". Why not use spell it out, e.g. using the official name of the protocol "HTTP/2" (vs "HTTP/1.1"), with a "const char *" instead?

The new configuration variable and the possible values it can take must be documented, of course. I think it would make the description far less embarrassing if we say "HTTP/2" etc. rather than "20", "11", etc.

Show 6 quoted lines
> @@ -284,6 +285,10 @@ static void process_curl_messages(void)
>  
>  static int http_options(const char *var, const char *value, void *cb)
>  {
> +	if (!strcmp("http.version",var)) {
> +		curl_http_version=git_config_int(var,value);
STYLE.  Missing SP after comma, and around assignment.
Show 11 quoted lines
> +		return 0;
> +	}
>  	if (!strcmp("http.sslverify", var)) {
>  		curl_ssl_verify = git_config_bool(var, value);
>  		return 0;
> @@ -806,6 +811,13 @@ static CURL *get_curl_handle(void)
>  		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
>  	}
>  
> +#if LIBCURL_VERSION_NUM >= 0x073100
> +	if(curl_http_version == 20){
STYLE. Missing SP before opening paren and after closing paren.
> +		/* CURL Enable HTTP2*/
STYLE. Missing SP before closing asterisk-slash.
> +		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
> +     }
> +#endif
Shouldn't this block also handle the other values, e.g. "11"?

I _think_ the curl_http_version variable (be it an deci-int, or a const char *) should be initialized to a value that you can use to notice that the configuration did not specify any, and then this part should become more like

	if (curl_http_version &&
	    !get_curl_http_version_opt(curl_http_version, &opt))
		curl_easy_setopt(result, CURL_HTTP_VERSION, opt);
with a helper function like this:
static int get_curl_http_version_opt(const char *version_string, long *opt)
{		
	int i;
	static struct {
		const char *name;
		lnog 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;
		}
	}
	return -1; /* not found */
}
which would make it trivial to support new values later.
>  #if LIBCURL_VERSION_NUM >= 0x070907
>  	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
>  #endif
Daniel Stenberg· Nov 7, 2018, 13:44 UTC · re: Force.Charlie-I via GitGitGadget · lore

Re: [PATCH 0/1] http: add support selecting http version

On Wed, 7 Nov 2018, Force.Charlie-I via GitGitGadget wrote:
> Normally, git doesn't need to set curl to select the HTTP version, it works 
> fine without HTTP2. Adding HTTP2 support is a icing on the cake.
Just a FYI:

Starting with libcurl 7.62.0 (released a week ago), it now defaults to the "2TLS" setting unless you tell it otherwise. With 2TLS, libcurl will attempt to use HTTP/2 for HTTPS URLs.

-- 
  / daniel.haxx.se
brian m. carlson· Nov 8, 2018, 01:18 UTC · re: Daniel Stenberg · lore

Re: [PATCH 0/1] http: add support selecting http version

On Wed, Nov 07, 2018 at 02:44:51PM +0100, Daniel Stenberg wrote:
Show 10 quoted lines
> On Wed, 7 Nov 2018, Force.Charlie-I via GitGitGadget wrote:
> 
> > Normally, git doesn't need to set curl to select the HTTP version, it
> > works fine without HTTP2. Adding HTTP2 support is a icing on the cake.
> 
> Just a FYI:
> 
> Starting with libcurl 7.62.0 (released a week ago), it now defaults to the
> "2TLS" setting unless you tell it otherwise. With 2TLS, libcurl will attempt
> to use HTTP/2 for HTTPS URLs.

With this information, I think I would rather we rely on libcurl to do this rather than putting it in Git. Users will automatically get the best supported protocol instead of having to configure it manually.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Junio C Hamano· Nov 8, 2018, 03:35 UTC · re: brian m. carlson · lore

Re: [PATCH 0/1] http: add support selecting http version

"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 15 quoted lines
> On Wed, Nov 07, 2018 at 02:44:51PM +0100, Daniel Stenberg wrote:
>> On Wed, 7 Nov 2018, Force.Charlie-I via GitGitGadget wrote:
>> 
>> > Normally, git doesn't need to set curl to select the HTTP version, it
>> > works fine without HTTP2. Adding HTTP2 support is a icing on the cake.
>> 
>> Just a FYI:
>> 
>> Starting with libcurl 7.62.0 (released a week ago), it now defaults to the
>> "2TLS" setting unless you tell it otherwise. With 2TLS, libcurl will attempt
>> to use HTTP/2 for HTTPS URLs.
>
> With this information, I think I would rather we rely on libcurl to do
> this rather than putting it in Git.  Users will automatically get the
> best supported protocol instead of having to configure it manually.

Yup. I suspect that the mechanism _might_ turn out to be useful to force downgrading, though.

Force.Charlie-I via GitGitGadget· Nov 8, 2018, 01:35 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v2 0/3] http: add support selecting http version

Normally, git doesn't need to set curl to select the HTTP version, it works fine without HTTP2. Adding HTTP2 support is a icing on the cake.

When http.version=20 is set, git will attempt to request the server using HTTP2. If the remote server does not support HTTP2, it is no different. Currently bitbucket supports HTTP2 and is available for testing.

example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=20 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (3):
  http: add support selecting http version
  support force use http 1.1
  fix curl version to support CURL_HTTP_VERSION_2TLS
 http.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v1:
 1:  4f5a935c43 = 1:  4f5a935c43 http: add support selecting http version
 -:  ---------- > 2:  06e9685d2b support force use http 1.1
 -:  ---------- > 3:  eee67d8356 fix curl version to support CURL_HTTP_VERSION_2TLS
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 01:35 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v2 1/3] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Show changes to http.c +12 −0
diff --git a/http.c b/http.c
index 3dc8c560d6..99cb04faba 100644
--- a/http.c
+++ b/http.c
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
+static int curl_http_version = 11;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -284,6 +285,10 @@ static void process_curl_messages(void)
 
 static int http_options(const char *var, const char *value, void *cb)
 {
+	if (!strcmp("http.version",var)) {
+		curl_http_version=git_config_int(var,value);
+		return 0;
+	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
 		return 0;
@@ -806,6 +811,13 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
+#if LIBCURL_VERSION_NUM >= 0x073100
+	if(curl_http_version == 20){
+		/* CURL Enable HTTP2*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
+     }
+#endif
+
 #if LIBCURL_VERSION_NUM >= 0x070907
 	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 #endif
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 01:35 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v2 2/3] support force use http 1.1

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
Show changes to http.c +9 −6
diff --git a/http.c b/http.c
index 99cb04faba..b2ec31aef5 100644
--- a/http.c
+++ b/http.c
@@ -48,7 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
-static int curl_http_version = 11;
+static int curl_http_version = 0;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -811,11 +811,14 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x073100
-	if(curl_http_version == 20){
-		/* CURL Enable HTTP2*/
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
-     }
+#if LIBCURL_VERSION_NUM >= 0x074700
+    // curl_http_version 0 is default.
+    if (curl_http_version == 20) {
+		/* Enable HTTP2 when request TLS*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
+    } else if (curl_http_version == 11) {
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
+    }
 #endif
 
 #if LIBCURL_VERSION_NUM >= 0x070907
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 01:35 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v2 3/3] fix curl version to support CURL_HTTP_VERSION_2TLS

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to http.c +2 −2
diff --git a/http.c b/http.c
index b2ec31aef5..86e454cff5 100644
--- a/http.c
+++ b/http.c
@@ -811,10 +811,10 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x074700
+#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
     // curl_http_version 0 is default.
     if (curl_http_version == 20) {
-		/* Enable HTTP2 when request TLS*/
+		/* Enable HTTP2*/
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
     } else if (curl_http_version == 11) {
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
-- 
gitgitgadget
Force.Charlie-I via GitGitGadget· Nov 8, 2018, 04:54 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v3 0/4] http: add support selecting http version

Normally, git doesn't need to set curl to select the HTTP version, it works fine without HTTP/2. Adding HTTP/2 support is a icing on the cake.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (4):
  http: add support selecting http version
  support force use http 1.1
  fix curl version to support CURL_HTTP_VERSION_2TLS
  http: change http.version value type
 http.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v2:
 1:  4f5a935c43 = 1:  4f5a935c43 http: add support selecting http version
 2:  06e9685d2b = 2:  06e9685d2b support force use http 1.1
 3:  eee67d8356 = 3:  eee67d8356 fix curl version to support CURL_HTTP_VERSION_2TLS
 -:  ---------- > 4:  ef975b6093 http: change http.version value type
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 04:54 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v3 1/4] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Show changes to http.c +12 −0
diff --git a/http.c b/http.c
index 3dc8c560d6..99cb04faba 100644
--- a/http.c
+++ b/http.c
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
+static int curl_http_version = 11;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -284,6 +285,10 @@ static void process_curl_messages(void)
 
 static int http_options(const char *var, const char *value, void *cb)
 {
+	if (!strcmp("http.version",var)) {
+		curl_http_version=git_config_int(var,value);
+		return 0;
+	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
 		return 0;
@@ -806,6 +811,13 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
+#if LIBCURL_VERSION_NUM >= 0x073100
+	if(curl_http_version == 20){
+		/* CURL Enable HTTP2*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
+     }
+#endif
+
 #if LIBCURL_VERSION_NUM >= 0x070907
 	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 #endif
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 04:55 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v3 2/4] support force use http 1.1

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
Show changes to http.c +9 −6
diff --git a/http.c b/http.c
index 99cb04faba..b2ec31aef5 100644
--- a/http.c
+++ b/http.c
@@ -48,7 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
-static int curl_http_version = 11;
+static int curl_http_version = 0;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -811,11 +811,14 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x073100
-	if(curl_http_version == 20){
-		/* CURL Enable HTTP2*/
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
-     }
+#if LIBCURL_VERSION_NUM >= 0x074700
+    // curl_http_version 0 is default.
+    if (curl_http_version == 20) {
+		/* Enable HTTP2 when request TLS*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
+    } else if (curl_http_version == 11) {
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
+    }
 #endif
 
 #if LIBCURL_VERSION_NUM >= 0x070907
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 04:55 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v3 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to http.c +2 −2
diff --git a/http.c b/http.c
index b2ec31aef5..86e454cff5 100644
--- a/http.c
+++ b/http.c
@@ -811,10 +811,10 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x074700
+#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
     // curl_http_version 0 is default.
     if (curl_http_version == 20) {
-		/* Enable HTTP2 when request TLS*/
+		/* Enable HTTP2*/
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
     } else if (curl_http_version == 11) {
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 04:55 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v3 4/4] http: change http.version value type

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)
Show changes to http.c +30 −9
diff --git a/http.c b/http.c
index 86e454cff5..0ad797caea 100644
--- a/http.c
+++ b/http.c
@@ -48,7 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
-static int curl_http_version = 0;
+static const char *curl_http_version = NULL;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -286,8 +286,7 @@ static void process_curl_messages(void)
 static int http_options(const char *var, const char *value, void *cb)
 {
 	if (!strcmp("http.version",var)) {
-		curl_http_version=git_config_int(var,value);
-		return 0;
+		return git_config_string(&curl_http_version, var, value);
 	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
@@ -794,6 +793,30 @@ 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;
+		}
+	}
+
+	return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
@@ -812,12 +835,10 @@ static CURL *get_curl_handle(void)
 	}
 
 #if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
-    // curl_http_version 0 is default.
-    if (curl_http_version == 20) {
-		/* Enable HTTP2*/
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
-    } else if (curl_http_version == 11) {
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
+    long opt=-1;
+    if (curl_http_version &&!get_curl_http_version_opt(curl_http_version, &opt)) {
+		/* Set request use http version */
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,opt);
     }
 #endif
 
-- 
gitgitgadget
Force.Charlie-I via GitGitGadget· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v4 0/4] http: add support selecting http version

Normally, git doesn't need to set curl to select the HTTP version, it works fine without HTTP/2. Adding HTTP/2 support is a icing on the cake.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (4):
  http: add support selecting http version
  support force use http 1.1
  fix curl version to support CURL_HTTP_VERSION_2TLS
  http: change http.version value type
 http.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v3:
 1:  4f5a935c43 = 1:  4f5a935c43 http: add support selecting http version
 2:  06e9685d2b = 2:  06e9685d2b support force use http 1.1
 3:  eee67d8356 = 3:  eee67d8356 fix curl version to support CURL_HTTP_VERSION_2TLS
 4:  ef975b6093 ! 4:  0a7794722b http: change http.version value type
     @@ -67,10 +67,12 @@
      -		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
      -    } else if (curl_http_version == 11) {
      -		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
     -+    long opt=-1;
     -+    if (curl_http_version &&!get_curl_http_version_opt(curl_http_version, &opt)) {
     -+		/* Set request use http version */
     -+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,opt);
     ++    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
       
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v4 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to http.c +2 −2
diff --git a/http.c b/http.c
index b2ec31aef5..86e454cff5 100644
--- a/http.c
+++ b/http.c
@@ -811,10 +811,10 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x074700
+#if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
     // curl_http_version 0 is default.
     if (curl_http_version == 20) {
-		/* Enable HTTP2 when request TLS*/
+		/* Enable HTTP2*/
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
     } else if (curl_http_version == 11) {
 		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v4 2/4] support force use http 1.1

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
Show changes to http.c +9 −6
diff --git a/http.c b/http.c
index 99cb04faba..b2ec31aef5 100644
--- a/http.c
+++ b/http.c
@@ -48,7 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
-static int curl_http_version = 11;
+static int curl_http_version = 0;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -811,11 +811,14 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
-#if LIBCURL_VERSION_NUM >= 0x073100
-	if(curl_http_version == 20){
-		/* CURL Enable HTTP2*/
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
-     }
+#if LIBCURL_VERSION_NUM >= 0x074700
+    // curl_http_version 0 is default.
+    if (curl_http_version == 20) {
+		/* Enable HTTP2 when request TLS*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
+    } else if (curl_http_version == 11) {
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
+    }
 #endif
 
 #if LIBCURL_VERSION_NUM >= 0x070907
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v4 4/4] http: change http.version value type

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)
Show changes to http.c +32 −9
diff --git a/http.c b/http.c
index 86e454cff5..d6f3c4ee80 100644
--- a/http.c
+++ b/http.c
@@ -48,7 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
-static int curl_http_version = 0;
+static const char *curl_http_version = NULL;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -286,8 +286,7 @@ static void process_curl_messages(void)
 static int http_options(const char *var, const char *value, void *cb)
 {
 	if (!strcmp("http.version",var)) {
-		curl_http_version=git_config_int(var,value);
-		return 0;
+		return git_config_string(&curl_http_version, var, value);
 	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
@@ -794,6 +793,30 @@ 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;
+		}
+	}
+
+	return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
@@ -812,12 +835,12 @@ static CURL *get_curl_handle(void)
 	}
 
 #if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
-    // curl_http_version 0 is default.
-    if (curl_http_version == 20) {
-		/* Enable HTTP2*/
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
-    } else if (curl_http_version == 11) {
-		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
+    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
 
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v4 1/4] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Show changes to http.c +12 −0
diff --git a/http.c b/http.c
index 3dc8c560d6..99cb04faba 100644
--- a/http.c
+++ b/http.c
@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
 
 static int curl_ssl_verify = -1;
 static int curl_ssl_try;
+static int curl_http_version = 11;
 static const char *ssl_cert;
 static const char *ssl_cipherlist;
 static const char *ssl_version;
@@ -284,6 +285,10 @@ static void process_curl_messages(void)
 
 static int http_options(const char *var, const char *value, void *cb)
 {
+	if (!strcmp("http.version",var)) {
+		curl_http_version=git_config_int(var,value);
+		return 0;
+	}
 	if (!strcmp("http.sslverify", var)) {
 		curl_ssl_verify = git_config_bool(var, value);
 		return 0;
@@ -806,6 +811,13 @@ static CURL *get_curl_handle(void)
 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
 	}
 
+#if LIBCURL_VERSION_NUM >= 0x073100
+	if(curl_http_version == 20){
+		/* CURL Enable HTTP2*/
+		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2);
+     }
+#endif
+
 #if LIBCURL_VERSION_NUM >= 0x070907
 	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
 #endif
-- 
gitgitgadget
Force.Charlie-I via GitGitGadget· Nov 8, 2018, 06:18 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v5 0/1] http: add support selecting http version

Normally, git doesn't need to set curl to select the HTTP version, it works fine without HTTP/2. Adding HTTP/2 support is a icing on the cake.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (1):
  http: add support selecting http version
 http.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v4:
 1:  4f5a935c43 < -:  ---------- http: add support selecting http version
 2:  06e9685d2b < -:  ---------- support force use http 1.1
 3:  eee67d8356 < -:  ---------- fix curl version to support CURL_HTTP_VERSION_2TLS
 4:  0a7794722b ! 1:  cdd93048ba http: change http.version value type
     @@ -1,6 +1,6 @@
      Author: Force Charlie <charlieio@outlook.com>
      
     -    http: change http.version value type
     +    http: add support selecting http version
      
          Signed-off-by: Force Charlie <charlieio@outlook.com>
      
     @@ -11,21 +11,20 @@
       
       static int curl_ssl_verify = -1;
       static int curl_ssl_try;
     --static int curl_http_version = 0;
      +static const char *curl_http_version = NULL;
       static const char *ssl_cert;
       static const char *ssl_cipherlist;
       static const char *ssl_version;
      @@
     + 
       static int http_options(const char *var, const char *value, void *cb)
       {
     - 	if (!strcmp("http.version",var)) {
     --		curl_http_version=git_config_int(var,value);
     --		return 0;
     ++	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;
      @@
       }
       #endif
     @@ -58,21 +57,19 @@
       {
       	CURL *result = curl_easy_init();
      @@
     + 		curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
       	}
       
     - #if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
     --    // curl_http_version 0 is default.
     --    if (curl_http_version == 20) {
     --		/* Enable HTTP2*/
     --		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
     --    } else if (curl_http_version == 11) {
     --		curl_easy_setopt(result, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
     ++#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
     - 
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 06:18 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v5 1/1] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>
Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
Show changes to http.c +38 −0
diff --git a/http.c b/http.c
index 3dc8c560d6..d6f3c4ee80 100644
--- a/http.c
+++ b/http.c
@@ -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,30 @@ 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;
+		}
+	}
+
+	return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
@@ -806,6 +834,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
-- 
gitgitgadget
Force.Charlie-I via GitGitGadget· Nov 8, 2018, 07:00 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v6 0/1] 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.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (1):
  http: add support selecting http version
 Documentation/config.txt |  9 +++++++++
 http.c                   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v6
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v5:
 1:  cdd93048ba ! 1:  93fda67198 http: add support selecting http version
     @@ -2,8 +2,38 @@
      
          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>
      
     +diff --git a/Documentation/config.txt b/Documentation/config.txt
     +--- a/Documentation/config.txt
     ++++ b/Documentation/config.txt
     +@@
     + 	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
     +
      diff --git a/http.c b/http.c
      --- a/http.c
      +++ b/http.c
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 07:00 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v6 1/1] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>

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>
---
 Documentation/config.txt |  9 +++++++++
 http.c                   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Show changes to 2 files +47 −0

Documentation/config.txt, http.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 41a9ff2b6a..f397942128 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1935,6 +1935,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
diff --git a/http.c b/http.c
index 3dc8c560d6..d6f3c4ee80 100644
--- a/http.c
+++ b/http.c
@@ -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,30 @@ 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;
+		}
+	}
+
+	return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
@@ -806,6 +834,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
-- 
gitgitgadget
Eric Sunshine· Nov 8, 2018, 18:02 UTC · re: Force Charlie via GitGitGadget · lore

Re: [PATCH v6 1/1] http: add support selecting http version

On Thu, Nov 8, 2018 at 2:00 AM Force Charlie via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 10 quoted lines
> 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>
> ---
> diff --git a/http.c b/http.c
> @@ -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)) {
Style: space after comma
Show 8 quoted lines
> +               return git_config_string(&curl_http_version, var, value);
> +       }
> @@ -806,6 +834,16 @@ static CURL *get_curl_handle(void)
> +    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);
Style: space after comma
> +               }
> +    }
Junio C Hamano· Nov 9, 2018, 02:57 UTC · re: Eric Sunshine · lore

Re: [PATCH v6 1/1] http: add support selecting http version

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 20 quoted lines
>> @@ -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)) {
>
> Style: space after comma
>
>> +               return git_config_string(&curl_http_version, var, value);
>> +       }
>> @@ -806,6 +834,16 @@ static CURL *get_curl_handle(void)
>> +    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);
>
> Style: space after comma
>
>> +               }
>> +    }
Thanks, both.  This is almost done, I think.
Junio C Hamano· Nov 9, 2018, 02:56 UTC · re: Force Charlie via GitGitGadget · lore

Re: [PATCH v6 1/1] http: add support selecting http version

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 19 quoted lines
> +#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;
> +		}
> +	}
> +

I wonder if we need to give a warning here about an unknown and ignored value, by calling something like

	warning("unknown value given to http.version: '%s'", version_string);

here. We should not trigger noisy warning while reading the configuration file looking for other variables unrelated to http.version but this codepath is followed only when we know we need to find out what value the variable is set to, so it probably is a good thing to do.

Thoughts?
Force.Charlie-I via GitGitGadget· Nov 8, 2018, 23:15 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v7 0/1] 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.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (1):
  http: add support selecting http version
 Documentation/config.txt |  9 +++++++++
 http.c                   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v7
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v6:
 1:  93fda67198 ! 1:  e26fc0d8c7 http: add support selecting http version
     @@ -49,7 +49,7 @@
       
       static int http_options(const char *var, const char *value, void *cb)
       {
     -+	if (!strcmp("http.version",var)) {
     ++	if (!strcmp("http.version", var)) {
      +		return git_config_string(&curl_http_version, var, value);
      +	}
       	if (!strcmp("http.sslverify", var)) {
     @@ -95,7 +95,7 @@
      +		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);
     ++			curl_easy_setopt(result, CURLOPT_HTTP_VERSION, opt);
      +		}
      +    }
      +#endif
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 8, 2018, 23:15 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v7 1/1] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>

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>
---
 Documentation/config.txt |  9 +++++++++
 http.c                   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
Show changes to 2 files +47 −0

Documentation/config.txt, http.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 41a9ff2b6a..f397942128 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1935,6 +1935,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
diff --git a/http.c b/http.c
index 3dc8c560d6..c22275bdee 100644
--- a/http.c
+++ b/http.c
@@ -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,30 @@ 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;
+		}
+	}
+
+	return -1; /* not found */
+}
+
+#endif
+
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
@@ -806,6 +834,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
-- 
gitgitgadget
Junio C Hamano· Nov 9, 2018, 03:52 UTC · re: Force Charlie via GitGitGadget · lore

Re: [PATCH v7 1/1] http: add support selecting http version

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 9 quoted lines
> +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
> +

I just wanted to make sure this formats well; it uses the same construct as used to make the list of allowed values for the next entry (sslVersion), so this should be fine.

Thanks.
Show 73 quoted lines
>  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 a/http.c b/http.c
> index 3dc8c560d6..c22275bdee 100644
> --- a/http.c
> +++ b/http.c
> @@ -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,30 @@ 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;
> +		}
> +	}
> +
> +	return -1; /* not found */
> +}
> +
> +#endif
> +
>  static CURL *get_curl_handle(void)
>  {
>  	CURL *result = curl_easy_init();
> @@ -806,6 +834,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
Force.Charlie-I via GitGitGadget· Nov 9, 2018, 03:44 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v8 0/1] 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.

This patch support force enable HTTP/2 or HTTP/1.1. 
example: 
GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
Force Charlie (1):
  http: add support selecting http version
 Documentation/config.txt |  9 +++++++++
 http.c                   | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v8
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v8
Pull-Request: https://github.com/gitgitgadget/git/pull/69
Range-diff vs v7:
 1:  e26fc0d8c7 ! 1:  71f8b71b34 http: add support selecting http version
     @@ -78,6 +78,7 @@
      +		}
      +	}
      +
     ++	warning("unknown value given to http.version: '%s'", version_string);
      +	return -1; /* not found */
      +}
      +
-- 
gitgitgadget
Force Charlie via GitGitGadget· Nov 9, 2018, 03:44 UTC · re: Force.Charlie-I via GitGitGadget · lore

[PATCH v8 1/1] http: add support selecting http version

From: Force Charlie <charlieio@outlook.com>

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>
---
 Documentation/config.txt |  9 +++++++++
 http.c                   | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
Show changes to 2 files +48 −0

Documentation/config.txt, http.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 41a9ff2b6a..f397942128 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1935,6 +1935,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
diff --git a/http.c b/http.c
index 3dc8c560d6..bc3274804e 100644
--- a/http.c
+++ b/http.c
@@ -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
-- 
gitgitgadget
Junio C Hamano· Nov 8, 2018, 06:14 UTC · re: Force.Charlie-I via GitGitGadget · lore

Re: [PATCH v3 0/4] http: add support selecting http version

"Force.Charlie-I via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 14 quoted lines
> Normally, git doesn't need to set curl to select the HTTP version, it works
> fine without HTTP/2. Adding HTTP/2 support is a icing on the cake.
>
> This patch support force enable HTTP/2 or HTTP/1.1. 
>
> example: 
>
> GIT_CURL_VERBOSE=1 git2 -c http.version=HTTP/2 ls-remote https://bitbucket.org/aquariusjay/deeplab-public-ver2.git
>
> Force Charlie (4):
>   http: add support selecting http version
>   support force use http 1.1
>   fix curl version to support CURL_HTTP_VERSION_2TLS
>   http: change http.version value type

When somebody reads over these four patches as a first-time reader, I think s/he notices a couple of things:

 - In the proposed log messages, there is no explanation on the
   reason why we are doing these changes.
 - Each of the steps n/4 (n > 1) looks more like "oops, it was a
   mistake that we did not do this in earlier patch, and here is to
   correct that".
 - There is no test or documentation.

I suspect that a single patch that updates http.c, Documentation/ and t/ at the same time should be sufficient for a change of this size.

Thanks.
Show 15 quoted lines
>  http.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
>
>
> base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
> Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-69%2Ffcharlie%2Fmaster-v3
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-69/fcharlie/master-v3
> Pull-Request: https://github.com/gitgitgadget/git/pull/69
>
> Range-diff vs v2:
>
>  1:  4f5a935c43 = 1:  4f5a935c43 http: add support selecting http version
>  2:  06e9685d2b = 2:  06e9685d2b support force use http 1.1
>  3:  eee67d8356 = 3:  eee67d8356 fix curl version to support CURL_HTTP_VERSION_2TLS
>  -:  ---------- > 4:  ef975b6093 http: change http.version value type

← back to recent threads