http: enable keep_error for HTTP requests
curl stops parsing a response when it sees a bad HTTP status code and it has CURLOPT_FAILONERROR set. This prevents GIT_CURL_VERBOSE to show HTTP headers on error. keep_error is an option to receive the HTTP response body for those error responses. By enabling this option, curl will process the HTTP response headers, and they're shown if GIT_CURL_VERBOSE is set. Signed-off-by: Masaya Suzuki <masayasuzuki@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
8dd2e88a92
commit
e6cf87b12d
42
http.c
42
http.c
|
@ -1837,8 +1837,6 @@ static int http_request(const char *url,
|
||||||
strbuf_addstr(&buf, "Pragma:");
|
strbuf_addstr(&buf, "Pragma:");
|
||||||
if (options && options->no_cache)
|
if (options && options->no_cache)
|
||||||
strbuf_addstr(&buf, " no-cache");
|
strbuf_addstr(&buf, " no-cache");
|
||||||
if (options && options->keep_error)
|
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
|
|
||||||
if (options && options->initial_request &&
|
if (options && options->initial_request &&
|
||||||
http_follow_config == HTTP_FOLLOW_INITIAL)
|
http_follow_config == HTTP_FOLLOW_INITIAL)
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
|
curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
|
@ -1856,6 +1854,7 @@ static int http_request(const char *url,
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
|
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
|
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
|
||||||
|
curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
|
||||||
|
|
||||||
ret = run_one_slot(slot, &results);
|
ret = run_one_slot(slot, &results);
|
||||||
|
|
||||||
|
@ -1950,29 +1949,26 @@ static int http_request_reauth(const char *url,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are using KEEP_ERROR, the previous request may have
|
* The previous request may have put cruft into our output stream; we
|
||||||
* put cruft into our output stream; we should clear it out before
|
* should clear it out before making our next request.
|
||||||
* making our next request.
|
|
||||||
*/
|
*/
|
||||||
if (options && options->keep_error) {
|
switch (target) {
|
||||||
switch (target) {
|
case HTTP_REQUEST_STRBUF:
|
||||||
case HTTP_REQUEST_STRBUF:
|
strbuf_reset(result);
|
||||||
strbuf_reset(result);
|
break;
|
||||||
break;
|
case HTTP_REQUEST_FILE:
|
||||||
case HTTP_REQUEST_FILE:
|
if (fflush(result)) {
|
||||||
if (fflush(result)) {
|
error_errno("unable to flush a file");
|
||||||
error_errno("unable to flush a file");
|
return HTTP_START_FAILED;
|
||||||
return HTTP_START_FAILED;
|
|
||||||
}
|
|
||||||
rewind(result);
|
|
||||||
if (ftruncate(fileno(result), 0) < 0) {
|
|
||||||
error_errno("unable to truncate a file");
|
|
||||||
return HTTP_START_FAILED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BUG("Unknown http_request target");
|
|
||||||
}
|
}
|
||||||
|
rewind(result);
|
||||||
|
if (ftruncate(fileno(result), 0) < 0) {
|
||||||
|
error_errno("unable to truncate a file");
|
||||||
|
return HTTP_START_FAILED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BUG("Unknown http_request target");
|
||||||
}
|
}
|
||||||
|
|
||||||
credential_fill(&http_auth);
|
credential_fill(&http_auth);
|
||||||
|
|
1
http.h
1
http.h
|
@ -146,7 +146,6 @@ extern char *get_remote_object_url(const char *url, const char *hex,
|
||||||
/* Options for http_get_*() */
|
/* Options for http_get_*() */
|
||||||
struct http_get_options {
|
struct http_get_options {
|
||||||
unsigned no_cache:1,
|
unsigned no_cache:1,
|
||||||
keep_error:1,
|
|
||||||
initial_request:1;
|
initial_request:1;
|
||||||
|
|
||||||
/* If non-NULL, returns the content-type of the response. */
|
/* If non-NULL, returns the content-type of the response. */
|
||||||
|
|
|
@ -380,7 +380,6 @@ static struct discovery *discover_refs(const char *service, int for_push)
|
||||||
http_options.extra_headers = &extra_headers;
|
http_options.extra_headers = &extra_headers;
|
||||||
http_options.initial_request = 1;
|
http_options.initial_request = 1;
|
||||||
http_options.no_cache = 1;
|
http_options.no_cache = 1;
|
||||||
http_options.keep_error = 1;
|
|
||||||
|
|
||||||
http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
|
http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
|
||||||
switch (http_ret) {
|
switch (http_ret) {
|
||||||
|
|
Loading…
Reference in New Issue