git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] http: add support selecting http version
@ 2018-11-07 13:33 Force.Charlie-I via GitGitGadget
  2018-11-07 13:33 ` [PATCH 1/1] " Force Charlie via GitGitGadget
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-07 13:33 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 1/1] http: add support selecting http version
  2018-11-07 13:33 [PATCH 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
@ 2018-11-07 13:33 ` Force Charlie via GitGitGadget
  2018-11-08  1:48   ` Junio C Hamano
  2018-11-07 13:44 ` [PATCH 0/1] " Daniel Stenberg
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
  2 siblings, 1 reply; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-07 13:33 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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;
 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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH 0/1] http: add support selecting http version
  2018-11-07 13:33 [PATCH 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-07 13:33 ` [PATCH 1/1] " Force Charlie via GitGitGadget
@ 2018-11-07 13:44 ` Daniel Stenberg
  2018-11-08  1:18   ` brian m. carlson
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
  2 siblings, 1 reply; 33+ messages in thread
From: Daniel Stenberg @ 2018-11-07 13:44 UTC (permalink / raw)
  To: Force.Charlie-I via GitGitGadget; +Cc: git, Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 0/1] http: add support selecting http version
  2018-11-07 13:44 ` [PATCH 0/1] " Daniel Stenberg
@ 2018-11-08  1:18   ` brian m. carlson
  2018-11-08  3:35     ` Junio C Hamano
  0 siblings, 1 reply; 33+ messages in thread
From: brian m. carlson @ 2018-11-08  1:18 UTC (permalink / raw)
  To: Daniel Stenberg; +Cc: Force.Charlie-I via GitGitGadget, git, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 791 bytes --]

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.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 0/3] http: add support selecting http version
  2018-11-07 13:33 [PATCH 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-07 13:33 ` [PATCH 1/1] " Force Charlie via GitGitGadget
  2018-11-07 13:44 ` [PATCH 0/1] " Daniel Stenberg
@ 2018-11-08  1:35 ` Force.Charlie-I via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 1/3] " Force Charlie via GitGitGadget
                     ` (3 more replies)
  2 siblings, 4 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08  1:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 1/3] http: add support selecting http version
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
@ 2018-11-08  1:35   ` Force Charlie via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 2/3] support force use http 1.1 Force Charlie via GitGitGadget
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  1:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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;
 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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 2/3] support force use http 1.1
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 1/3] " Force Charlie via GitGitGadget
@ 2018-11-08  1:35   ` Force Charlie via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 3/3] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  3 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  1:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 3/3] fix curl version to support CURL_HTTP_VERSION_2TLS
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 1/3] " Force Charlie via GitGitGadget
  2018-11-08  1:35   ` [PATCH v2 2/3] support force use http 1.1 Force Charlie via GitGitGadget
@ 2018-11-08  1:35   ` Force Charlie via GitGitGadget
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  3 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  1:35 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH 1/1] http: add support selecting http version
  2018-11-07 13:33 ` [PATCH 1/1] " Force Charlie via GitGitGadget
@ 2018-11-08  1:48   ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-08  1:48 UTC (permalink / raw)
  To: Force Charlie via GitGitGadget; +Cc: git, Force Charlie

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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.

> @@ -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.

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 0/1] http: add support selecting http version
  2018-11-08  1:18   ` brian m. carlson
@ 2018-11-08  3:35     ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-08  3:35 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Daniel Stenberg, Force.Charlie-I via GitGitGadget, git

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> 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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v3 0/4] http: add support selecting http version
  2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
                     ` (2 preceding siblings ...)
  2018-11-08  1:35   ` [PATCH v2 3/3] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
@ 2018-11-08  4:54   ` Force.Charlie-I via GitGitGadget
  2018-11-08  4:54     ` [PATCH v3 1/4] " Force Charlie via GitGitGadget
                       ` (5 more replies)
  3 siblings, 6 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08  4:54 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v3 1/4] http: add support selecting http version
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
@ 2018-11-08  4:54     ` Force Charlie via GitGitGadget
  2018-11-08  4:55     ` [PATCH v3 2/4] support force use http 1.1 Force Charlie via GitGitGadget
                       ` (4 subsequent siblings)
  5 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  4:54 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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;
 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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 2/4] support force use http 1.1
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  4:54     ` [PATCH v3 1/4] " Force Charlie via GitGitGadget
@ 2018-11-08  4:55     ` Force Charlie via GitGitGadget
  2018-11-08  4:55     ` [PATCH v3 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
                       ` (3 subsequent siblings)
  5 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  4:55 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  4:54     ` [PATCH v3 1/4] " Force Charlie via GitGitGadget
  2018-11-08  4:55     ` [PATCH v3 2/4] support force use http 1.1 Force Charlie via GitGitGadget
@ 2018-11-08  4:55     ` Force Charlie via GitGitGadget
  2018-11-08  4:55     ` [PATCH v3 4/4] http: change http.version value type Force Charlie via GitGitGadget
                       ` (2 subsequent siblings)
  5 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  4:55 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 4/4] http: change http.version value type
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
                       ` (2 preceding siblings ...)
  2018-11-08  4:55     ` [PATCH v3 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
@ 2018-11-08  4:55     ` Force Charlie via GitGitGadget
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  6:14     ` [PATCH v3 0/4] " Junio C Hamano
  5 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  4:55 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 0/4] http: add support selecting http version
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
                       ` (3 preceding siblings ...)
  2018-11-08  4:55     ` [PATCH v3 4/4] http: change http.version value type Force Charlie via GitGitGadget
@ 2018-11-08  6:14     ` Force.Charlie-I via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 1/4] " Force Charlie via GitGitGadget
                         ` (4 more replies)
  2018-11-08  6:14     ` [PATCH v3 0/4] " Junio C Hamano
  5 siblings, 5 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08  6:14 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v4 1/4] http: add support selecting http version
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
@ 2018-11-08  6:14       ` Force Charlie via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 2/4] support force use http 1.1 Force Charlie via GitGitGadget
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  6:14 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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;
 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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 2/4] support force use http 1.1
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 1/4] " Force Charlie via GitGitGadget
@ 2018-11-08  6:14       ` Force Charlie via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  6:14 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 1/4] " Force Charlie via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 2/4] support force use http 1.1 Force Charlie via GitGitGadget
@ 2018-11-08  6:14       ` Force Charlie via GitGitGadget
  2018-11-08  6:14       ` [PATCH v4 4/4] http: change http.version value type Force Charlie via GitGitGadget
  2018-11-08  6:18       ` [PATCH v5 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
  4 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  6:14 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 4/4] http: change http.version value type
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
                         ` (2 preceding siblings ...)
  2018-11-08  6:14       ` [PATCH v4 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
@ 2018-11-08  6:14       ` Force Charlie via GitGitGadget
  2018-11-08  6:18       ` [PATCH v5 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
  4 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  6:14 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v3 0/4] http: add support selecting http version
  2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
                       ` (4 preceding siblings ...)
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
@ 2018-11-08  6:14     ` Junio C Hamano
  5 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-08  6:14 UTC (permalink / raw)
  To: Force.Charlie-I via GitGitGadget; +Cc: git

"Force.Charlie-I via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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.


>  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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v5 0/1] http: add support selecting http version
  2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
                         ` (3 preceding siblings ...)
  2018-11-08  6:14       ` [PATCH v4 4/4] http: change http.version value type Force Charlie via GitGitGadget
@ 2018-11-08  6:18       ` Force.Charlie-I via GitGitGadget
  2018-11-08  6:18         ` [PATCH v5 1/1] " Force Charlie via GitGitGadget
  2018-11-08  7:00         ` [PATCH v6 0/1] " Force.Charlie-I via GitGitGadget
  4 siblings, 2 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08  6:18 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v5 1/1] http: add support selecting http version
  2018-11-08  6:18       ` [PATCH v5 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
@ 2018-11-08  6:18         ` Force Charlie via GitGitGadget
  2018-11-08  7:00         ` [PATCH v6 0/1] " Force.Charlie-I via GitGitGadget
  1 sibling, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  6:18 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

From: Force Charlie <charlieio@outlook.com>

Signed-off-by: Force Charlie <charlieio@outlook.com>
---
 http.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v6 0/1] http: add support selecting http version
  2018-11-08  6:18       ` [PATCH v5 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
  2018-11-08  6:18         ` [PATCH v5 1/1] " Force Charlie via GitGitGadget
@ 2018-11-08  7:00         ` Force.Charlie-I via GitGitGadget
  2018-11-08  7:00           ` [PATCH v6 1/1] " Force Charlie via GitGitGadget
  2018-11-08 23:15           ` [PATCH v7 0/1] " Force.Charlie-I via GitGitGadget
  1 sibling, 2 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08  7:00 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v6 1/1] http: add support selecting http version
  2018-11-08  7:00         ` [PATCH v6 0/1] " Force.Charlie-I via GitGitGadget
@ 2018-11-08  7:00           ` Force Charlie via GitGitGadget
  2018-11-08 18:02             ` Eric Sunshine
  2018-11-09  2:56             ` Junio C Hamano
  2018-11-08 23:15           ` [PATCH v7 0/1] " Force.Charlie-I via GitGitGadget
  1 sibling, 2 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08  7:00 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v6 1/1] http: add support selecting http version
  2018-11-08  7:00           ` [PATCH v6 1/1] " Force Charlie via GitGitGadget
@ 2018-11-08 18:02             ` Eric Sunshine
  2018-11-09  2:57               ` Junio C Hamano
  2018-11-09  2:56             ` Junio C Hamano
  1 sibling, 1 reply; 33+ messages in thread
From: Eric Sunshine @ 2018-11-08 18:02 UTC (permalink / raw)
  To: gitgitgadget; +Cc: Git List, Junio C Hamano, charlieio

On Thu, Nov 8, 2018 at 2:00 AM Force Charlie via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> 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

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

> +               }
> +    }

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v7 0/1] http: add support selecting http version
  2018-11-08  7:00         ` [PATCH v6 0/1] " Force.Charlie-I via GitGitGadget
  2018-11-08  7:00           ` [PATCH v6 1/1] " Force Charlie via GitGitGadget
@ 2018-11-08 23:15           ` Force.Charlie-I via GitGitGadget
  2018-11-08 23:15             ` [PATCH v7 1/1] " Force Charlie via GitGitGadget
  2018-11-09  3:44             ` [PATCH v8 0/1] " Force.Charlie-I via GitGitGadget
  1 sibling, 2 replies; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-08 23:15 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v7 1/1] http: add support selecting http version
  2018-11-08 23:15           ` [PATCH v7 0/1] " Force.Charlie-I via GitGitGadget
@ 2018-11-08 23:15             ` Force Charlie via GitGitGadget
  2018-11-09  3:52               ` Junio C Hamano
  2018-11-09  3:44             ` [PATCH v8 0/1] " Force.Charlie-I via GitGitGadget
  1 sibling, 1 reply; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-08 23:15 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v6 1/1] http: add support selecting http version
  2018-11-08  7:00           ` [PATCH v6 1/1] " Force Charlie via GitGitGadget
  2018-11-08 18:02             ` Eric Sunshine
@ 2018-11-09  2:56             ` Junio C Hamano
  1 sibling, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-09  2:56 UTC (permalink / raw)
  To: Force Charlie via GitGitGadget; +Cc: git, Force Charlie, Eric Sunshine

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +#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?


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v6 1/1] http: add support selecting http version
  2018-11-08 18:02             ` Eric Sunshine
@ 2018-11-09  2:57               ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-09  2:57 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: gitgitgadget, Git List, charlieio

Eric Sunshine <sunshine@sunshineco.com> writes:

>> @@ -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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v8 0/1] http: add support selecting http version
  2018-11-08 23:15           ` [PATCH v7 0/1] " Force.Charlie-I via GitGitGadget
  2018-11-08 23:15             ` [PATCH v7 1/1] " Force Charlie via GitGitGadget
@ 2018-11-09  3:44             ` Force.Charlie-I via GitGitGadget
  2018-11-09  3:44               ` [PATCH v8 1/1] " Force Charlie via GitGitGadget
  1 sibling, 1 reply; 33+ messages in thread
From: Force.Charlie-I via GitGitGadget @ 2018-11-09  3:44 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v8 1/1] http: add support selecting http version
  2018-11-09  3:44             ` [PATCH v8 0/1] " Force.Charlie-I via GitGitGadget
@ 2018-11-09  3:44               ` Force Charlie via GitGitGadget
  0 siblings, 0 replies; 33+ messages in thread
From: Force Charlie via GitGitGadget @ 2018-11-09  3:44 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Force Charlie

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

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v7 1/1] http: add support selecting http version
  2018-11-08 23:15             ` [PATCH v7 1/1] " Force Charlie via GitGitGadget
@ 2018-11-09  3:52               ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2018-11-09  3:52 UTC (permalink / raw)
  To: Force Charlie via GitGitGadget; +Cc: git, Force Charlie

"Force Charlie via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +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.

>  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

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2018-11-09  3:52 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-07 13:33 [PATCH 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
2018-11-07 13:33 ` [PATCH 1/1] " Force Charlie via GitGitGadget
2018-11-08  1:48   ` Junio C Hamano
2018-11-07 13:44 ` [PATCH 0/1] " Daniel Stenberg
2018-11-08  1:18   ` brian m. carlson
2018-11-08  3:35     ` Junio C Hamano
2018-11-08  1:35 ` [PATCH v2 0/3] " Force.Charlie-I via GitGitGadget
2018-11-08  1:35   ` [PATCH v2 1/3] " Force Charlie via GitGitGadget
2018-11-08  1:35   ` [PATCH v2 2/3] support force use http 1.1 Force Charlie via GitGitGadget
2018-11-08  1:35   ` [PATCH v2 3/3] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
2018-11-08  4:54   ` [PATCH v3 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
2018-11-08  4:54     ` [PATCH v3 1/4] " Force Charlie via GitGitGadget
2018-11-08  4:55     ` [PATCH v3 2/4] support force use http 1.1 Force Charlie via GitGitGadget
2018-11-08  4:55     ` [PATCH v3 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
2018-11-08  4:55     ` [PATCH v3 4/4] http: change http.version value type Force Charlie via GitGitGadget
2018-11-08  6:14     ` [PATCH v4 0/4] http: add support selecting http version Force.Charlie-I via GitGitGadget
2018-11-08  6:14       ` [PATCH v4 1/4] " Force Charlie via GitGitGadget
2018-11-08  6:14       ` [PATCH v4 2/4] support force use http 1.1 Force Charlie via GitGitGadget
2018-11-08  6:14       ` [PATCH v4 3/4] fix curl version to support CURL_HTTP_VERSION_2TLS Force Charlie via GitGitGadget
2018-11-08  6:14       ` [PATCH v4 4/4] http: change http.version value type Force Charlie via GitGitGadget
2018-11-08  6:18       ` [PATCH v5 0/1] http: add support selecting http version Force.Charlie-I via GitGitGadget
2018-11-08  6:18         ` [PATCH v5 1/1] " Force Charlie via GitGitGadget
2018-11-08  7:00         ` [PATCH v6 0/1] " Force.Charlie-I via GitGitGadget
2018-11-08  7:00           ` [PATCH v6 1/1] " Force Charlie via GitGitGadget
2018-11-08 18:02             ` Eric Sunshine
2018-11-09  2:57               ` Junio C Hamano
2018-11-09  2:56             ` Junio C Hamano
2018-11-08 23:15           ` [PATCH v7 0/1] " Force.Charlie-I via GitGitGadget
2018-11-08 23:15             ` [PATCH v7 1/1] " Force Charlie via GitGitGadget
2018-11-09  3:52               ` Junio C Hamano
2018-11-09  3:44             ` [PATCH v8 0/1] " Force.Charlie-I via GitGitGadget
2018-11-09  3:44               ` [PATCH v8 1/1] " Force Charlie via GitGitGadget
2018-11-08  6:14     ` [PATCH v3 0/4] " Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).