git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Force Charlie via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Force Charlie <charlieio@outlook.com>
Subject: Re: [PATCH 1/1] http: add support selecting http version
Date: Thu, 08 Nov 2018 10:48:00 +0900	[thread overview]
Message-ID: <xmqqwopo8hm7.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <4f5a935c4355794effb23c979dcbaf77ed33da26.1541597633.git.gitgitgadget@gmail.com> (Force Charlie via GitGitGadget's message of "Wed, 07 Nov 2018 05:33:56 -0800 (PST)")

"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

  reply	other threads:[~2018-11-08  1:48 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqwopo8hm7.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=charlieio@outlook.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).