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>
Masaya Suzuki committed
Jan 10, 2019 at 11:33 UTC
e6cf87b12d3b85b31637c865bbfaed62c3e59e94
3 files changed
+19
-25
http.c
+19
-23
@@ -1837,8 +1837,6 @@ static int http_request(const char *url,
1837
strbuf_addstr(&buf, "Pragma:");
1838
if (options && options->no_cache)
1839
strbuf_addstr(&buf, " no-cache");
1840
- if (options && options->keep_error)
1841
- curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
1840
if (options && options->initial_request &&
1841
http_follow_config == HTTP_FOLLOW_INITIAL)
1842
curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
@@ -1856,6 +1854,7 @@ static int http_request(const char *url,
1854
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
1855
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
1856
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
1857
+ curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
1858
1859
ret = run_one_slot(slot, &results);
1860
@@ -1950,29 +1949,26 @@ static int http_request_reauth(const char *url,
1949
return ret;
1950
1951
/*
1953
- * If we are using KEEP_ERROR, the previous request may have
1954
- * put cruft into our output stream; we should clear it out before
1955
- * making our next request.
1952
+ * The previous request may have put cruft into our output stream; we
1953
+ * should clear it out before making our next request.
1954
*/
1957
- if (options && options->keep_error) {
1958
- switch (target) {
1959
- case HTTP_REQUEST_STRBUF:
1960
- strbuf_reset(result);
1961
- break;
1962
- case HTTP_REQUEST_FILE:
1963
- if (fflush(result)) {
1964
- error_errno("unable to flush a file");
1965
- return HTTP_START_FAILED;
1966
- }
1967
- rewind(result);
1968
- if (ftruncate(fileno(result), 0) < 0) {
1969
- error_errno("unable to truncate a file");
1970
- return HTTP_START_FAILED;
1971
- }
1972
- break;
1973
- default:
1974
- BUG("Unknown http_request target");
1955
+ switch (target) {
1956
+ case HTTP_REQUEST_STRBUF:
1957
+ strbuf_reset(result);
1958
+ break;
1959
+ case HTTP_REQUEST_FILE:
1960
+ if (fflush(result)) {
1961
+ error_errno("unable to flush a file");
1962
+ return HTTP_START_FAILED;
1963
+ }
1964
+ rewind(result);
1965
+ if (ftruncate(fileno(result), 0) < 0) {
1966
+ error_errno("unable to truncate a file");
1967
+ return HTTP_START_FAILED;
1968
}
1969
+ break;
1970
+ default:
1971
+ BUG("Unknown http_request target");
1972
}
1973
1974
credential_fill(&http_auth);
http.h
-1
@@ -146,7 +146,6 @@ extern char *get_remote_object_url(const char *url, const char *hex,
146
/* Options for http_get_*() */
147
struct http_get_options {
148
unsigned no_cache:1,
149
- keep_error:1,
149
initial_request:1;
150
151
/* If non-NULL, returns the content-type of the response. */
remote-curl.c
-1
@@ -380,7 +380,6 @@ static struct discovery *discover_refs(const char *service, int for_push)
380
http_options.extra_headers = &extra_headers;
381
http_options.initial_request = 1;
382
http_options.no_cache = 1;
383
- http_options.keep_error = 1;
383
384
http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
385
switch (http_ret) {