@@ -48,6 +48,7 @@ char curl_errorstr[CURL_ERROR_SIZE];
4848
4949static int curl_ssl_verify = -1 ;
5050static int curl_ssl_try ;
51+ static const char * curl_http_version = NULL ;
5152static const char * ssl_cert ;
5253static const char * ssl_cipherlist ;
5354static const char * ssl_version ;
@@ -284,6 +285,9 @@ static void process_curl_messages(void)
284285
285286static int http_options (const char * var , const char * value , void * cb )
286287{
288+ if (!strcmp ("http.version" , var )) {
289+ return git_config_string (& curl_http_version , var , value );
290+ }
287291 if (!strcmp ("http.sslverify" , var )) {
288292 curl_ssl_verify = git_config_bool (var , value );
289293 return 0 ;
@@ -789,6 +793,31 @@ static long get_curl_allowed_protocols(int from_user)
789793}
790794#endif
791795
796+ #if LIBCURL_VERSION_NUM >=0x072f00
797+ static int get_curl_http_version_opt (const char * version_string , long * opt )
798+ {
799+ int i ;
800+ static struct {
801+ const char * name ;
802+ long opt_token ;
803+ } choice [] = {
804+ { "HTTP/1.1" , CURL_HTTP_VERSION_1_1 },
805+ { "HTTP/2" , CURL_HTTP_VERSION_2 }
806+ };
807+
808+ for (i = 0 ; i < ARRAY_SIZE (choice ); i ++ ) {
809+ if (!strcmp (version_string , choice [i ].name )) {
810+ * opt = choice [i ].opt_token ;
811+ return 0 ;
812+ }
813+ }
814+
815+ warning ("unknown value given to http.version: '%s'" , version_string );
816+ return -1 ; /* not found */
817+ }
818+
819+ #endif
820+
792821static CURL * get_curl_handle (void )
793822{
794823 CURL * result = curl_easy_init ();
@@ -806,6 +835,16 @@ static CURL *get_curl_handle(void)
806835 curl_easy_setopt (result , CURLOPT_SSL_VERIFYHOST , 2 );
807836 }
808837
838+ #if LIBCURL_VERSION_NUM >= 0x072f00 // 7.47.0
839+ if (curl_http_version ) {
840+ long opt ;
841+ if (!get_curl_http_version_opt (curl_http_version , & opt )) {
842+ /* Set request use http version */
843+ curl_easy_setopt (result , CURLOPT_HTTP_VERSION , opt );
844+ }
845+ }
846+ #endif
847+
809848#if LIBCURL_VERSION_NUM >= 0x070907
810849 curl_easy_setopt (result , CURLOPT_NETRC , CURL_NETRC_OPTIONAL );
811850#endif
0 commit comments