From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS63949 64.71.152.0/24 X-Spam-Status: No, score=-3.2 required=3.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from 80x24.org (unknown [64.71.152.64]) by dcvr.yhbt.net (Postfix) with ESMTP id 3D70420248 for ; Fri, 22 Mar 2019 16:34:49 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] WIP from peff Date: Fri, 22 Mar 2019 16:34:49 +0000 Message-Id: <20190322163449.25362-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- http-walker.c | 17 ++++++----------- http.c | 14 +++++++++----- http.h | 6 ++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/http-walker.c b/http-walker.c index 8ae5d76c6a..608e06d397 100644 --- a/http-walker.c +++ b/http-walker.c @@ -98,6 +98,9 @@ static void process_object_response(void *callback_data) process_http_object_request(obj_req->req); obj_req->state = COMPLETE; + normalize_curl_result(&obj_req->req->curl_result, + obj_req->req->http_code); + /* Use alternates if necessary */ if (missing_target(obj_req->req)) { fetch_alternates(walker, alt->base); @@ -208,6 +211,8 @@ static void process_alternates_response(void *callback_data) char *data; int i = 0; + normalize_curl_result(&slot->curl_result, slot->http_code); + if (alt_req->http_specific) { if (slot->curl_result != CURLE_OK || !alt_req->buffer->len) { @@ -518,17 +523,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) req->localfile = -1; } - /* - * we turned off CURLOPT_FAILONERROR to avoid losing a - * persistent connection and got CURLE_OK. - */ - if (req->http_code >= 300 && req->curl_result == CURLE_OK && - (starts_with(req->url, "http://") || - starts_with(req->url, "https://"))) { - req->curl_result = CURLE_HTTP_RETURNED_ERROR; - xsnprintf(req->errorstr, sizeof(req->errorstr), - "HTTP request failed"); - } + normalize_curl_result(&req->curl_result, req->http_code); if (obj_req->state == ABORTED) { ret = error("Request for %s aborted", hex); diff --git a/http.c b/http.c index a32ad36ddf..696d655f31 100644 --- a/http.c +++ b/http.c @@ -1544,7 +1544,7 @@ char *get_remote_object_url(const char *url, const char *hex, return strbuf_detach(&buf, NULL); } -static int handle_curl_result(struct slot_results *results) +void normalize_curl_result(CURLcode *result, long http_code) { /* * If we see a failing http code with CURLE_OK, we have turned off @@ -1554,9 +1554,8 @@ static int handle_curl_result(struct slot_results *results) * Likewise, if we see a redirect (30x code), that means we turned off * redirect-following, and we should treat the result as an error. */ - if (results->curl_result == CURLE_OK && - results->http_code >= 300) { - results->curl_result = CURLE_HTTP_RETURNED_ERROR; + if (*result == CURLE_OK && http_code >= 400) { + *result = CURLE_HTTP_RETURNED_ERROR; /* * Normally curl will already have put the "reason phrase" * from the server into curl_errorstr; unfortunately without @@ -1565,8 +1564,13 @@ static int handle_curl_result(struct slot_results *results) */ xsnprintf(curl_errorstr, sizeof(curl_errorstr), "The requested URL returned error: %ld", - results->http_code); + http_code); } +} + +static int handle_curl_result(struct slot_results *results) +{ + normalize_curl_result(&results->curl_result, results->http_code); if (results->curl_result == CURLE_OK) { credential_approve(&http_auth); diff --git a/http.h b/http.h index 4eb4e808e5..f5549ea1c2 100644 --- a/http.h +++ b/http.h @@ -136,6 +136,12 @@ static inline int missing__target(int code, int result) #define missing_target(a) missing__target((a)->http_code, (a)->curl_result) +/* + * Yuck, we cannot just pass the struct containing these because we store the + * results in various structs. + */ +void normalize_curl_result(CURLcode *result, long http_code); + /* Helpers for modifying and creating URLs */ extern void append_remote_object_url(struct strbuf *buf, const char *url, const char *hex, -- EW