@@ -7,6 +7,12 @@ int active_requests;
77int http_is_verbose ;
88size_t http_post_buffer = 16 * LARGE_PACKET_MAX ;
99
10+ #if LIBCURL_VERSION_NUM >= 0x070a06
11+ #define LIBCURL_CAN_HANDLE_AUTH_ANY
12+ #endif
13+
14+ static int min_curl_sessions = 1 ;
15+ static int curl_session_count ;
1016#ifdef USE_CURL_MULTI
1117static int max_requests = -1 ;
1218static CURLM * curlm ;
@@ -152,6 +158,14 @@ static int http_options(const char *var, const char *value, void *cb)
152158 ssl_cert_password_required = 1 ;
153159 return 0 ;
154160 }
161+ if (!strcmp ("http.minsessions" , var )) {
162+ min_curl_sessions = git_config_int (var , value );
163+ #ifndef USE_CURL_MULTI
164+ if (min_curl_sessions > 1 )
165+ min_curl_sessions = 1 ;
166+ #endif
167+ return 0 ;
168+ }
155169#ifdef USE_CURL_MULTI
156170 if (!strcmp ("http.maxrequests" , var )) {
157171 max_requests = git_config_int (var , value );
@@ -230,6 +244,9 @@ static CURL *get_curl_handle(void)
230244#if LIBCURL_VERSION_NUM >= 0x070907
231245 curl_easy_setopt (result , CURLOPT_NETRC , CURL_NETRC_OPTIONAL );
232246#endif
247+ #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
248+ curl_easy_setopt (result , CURLOPT_HTTPAUTH , CURLAUTH_ANY );
249+ #endif
233250
234251 init_curl_http_auth (result );
235252
@@ -372,6 +389,7 @@ void http_init(struct remote *remote)
372389 if (curl_ssl_verify == -1 )
373390 curl_ssl_verify = 1 ;
374391
392+ curl_session_count = 0 ;
375393#ifdef USE_CURL_MULTI
376394 if (max_requests < 1 )
377395 max_requests = DEFAULT_MAX_REQUESTS ;
@@ -480,6 +498,7 @@ struct active_request_slot *get_active_slot(void)
480498#else
481499 slot -> curl = curl_easy_duphandle (curl_default );
482500#endif
501+ curl_session_count ++ ;
483502 }
484503
485504 active_requests ++ ;
@@ -558,9 +577,11 @@ void fill_active_slots(void)
558577 }
559578
560579 while (slot != NULL ) {
561- if (!slot -> in_use && slot -> curl != NULL ) {
580+ if (!slot -> in_use && slot -> curl != NULL
581+ && curl_session_count > min_curl_sessions ) {
562582 curl_easy_cleanup (slot -> curl );
563583 slot -> curl = NULL ;
584+ curl_session_count -- ;
564585 }
565586 slot = slot -> next ;
566587 }
@@ -633,12 +654,13 @@ static void closedown_active_slot(struct active_request_slot *slot)
633654void release_active_slot (struct active_request_slot * slot )
634655{
635656 closedown_active_slot (slot );
636- if (slot -> curl ) {
657+ if (slot -> curl && curl_session_count > min_curl_sessions ) {
637658#ifdef USE_CURL_MULTI
638659 curl_multi_remove_handle (curlm , slot -> curl );
639660#endif
640661 curl_easy_cleanup (slot -> curl );
641662 slot -> curl = NULL ;
663+ curl_session_count -- ;
642664 }
643665#ifdef USE_CURL_MULTI
644666 fill_active_slots ();
0 commit comments