http: support file handles for HTTP_KEEP_ERROR
HTTP_KEEP_ERROR makes it easy to debug HTTP transport errors. In order to make HTTP_KEEP_ERROR enabled for all requests, file handles need to be supported. 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
8dd2e88a923bd24775182f0a507c993e06a0aacb
1 file changed
+13
-3
http.c
+13
-3
@@ -1952,16 +1952,26 @@ static int http_request_reauth(const char *url,
1952
/*
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. We only know how to do this for
1956
- * the strbuf case, but that is enough to satisfy current callers.
1955
+ * making our next request.
1956
*/
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:
1964
- BUG("HTTP_KEEP_ERROR is only supported with strbufs");
1974
+ BUG("Unknown http_request target");
1975
}
1976
}
1977