X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=http.c;h=08769cc7cd4282a485fb9cd22c4ecfa97096a419;hb=ae448e3854d8b6e7e37aa88fa3917f5dd97f3210;hp=eefb0f03d2f7ac30163e69b842f6943987cf9351;hpb=c8568e139ed2149fbfb7ef9a8d819d5b6b7c554f;p=git.git diff --git a/http.c b/http.c index eefb0f03..08769cc7 100644 --- a/http.c +++ b/http.c @@ -25,7 +25,6 @@ long curl_low_speed_limit = -1; long curl_low_speed_time = -1; struct curl_slist *pragma_header; -struct curl_slist *no_range_header; struct active_request_slot *active_queue_head = NULL; @@ -192,6 +191,11 @@ static CURL* get_curl_handle(void) curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1); + if (getenv("GIT_CURL_VERBOSE")) + curl_easy_setopt(result, CURLOPT_VERBOSE, 1); + + curl_easy_setopt(result, CURLOPT_USERAGENT, GIT_USER_AGENT); + return result; } @@ -203,7 +207,6 @@ void http_init(void) curl_global_init(CURL_GLOBAL_ALL); pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache"); - no_range_header = curl_slist_append(no_range_header, "Range:"); #ifdef USE_CURL_MULTI { @@ -283,7 +286,8 @@ void http_cleanup(void) curl_multi_cleanup(curlm); #endif curl_global_cleanup(); - + + curl_slist_free_all(pragma_header); } struct active_request_slot *get_active_slot(void) @@ -336,11 +340,17 @@ struct active_request_slot *get_active_slot(void) slot->in_use = 1; slot->local = NULL; slot->results = NULL; + slot->finished = NULL; slot->callback_data = NULL; slot->callback_func = NULL; + curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_range_header); curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr); + curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL); + curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, NULL); + curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, NULL); + curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0); + curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); return slot; } @@ -386,8 +396,10 @@ void run_active_slot(struct active_request_slot *slot) fd_set excfds; int max_fd; struct timeval select_timeout; + int finished = 0; - while (slot->in_use) { + slot->finished = &finished; + while (!finished) { data_received = 0; step_active_slots(); @@ -417,12 +429,35 @@ void run_active_slot(struct active_request_slot *slot) #endif } -static void finish_active_slot(struct active_request_slot *slot) +static void closedown_active_slot(struct active_request_slot *slot) { active_requests--; slot->in_use = 0; +} + +void release_active_slot(struct active_request_slot *slot) +{ + closedown_active_slot(slot); + if (slot->curl) { +#ifdef USE_CURL_MULTI + curl_multi_remove_handle(curlm, slot->curl); +#endif + curl_easy_cleanup(slot->curl); + slot->curl = NULL; + } +#ifdef USE_CURL_MULTI + fill_active_slots(); +#endif +} + +static void finish_active_slot(struct active_request_slot *slot) +{ + closedown_active_slot(slot); curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code); + if (slot->finished != NULL) + (*slot->finished) = 1; + /* Store slot results so they can be read after the slot is reused */ if (slot->results != NULL) { slot->results->curl_result = slot->curl_result;