remote-curl: accept all encodings supported by curl

Configure curl to accept all encodings which curl supports instead of only accepting gzip responses. This fixes an issue when using an installation of curl which is built without the "zlib" feature. Since aa90b9697 (Enable info/refs gzip decompression in HTTP client, 2012-09-19) we end up requesting "gzip" encoding anyway despite libcurl not being able to decode it. Worse, instead of getting a clear error message indicating so, we end up falling back to "dumb" http, producing a confusing and difficult to debug result. Since curl doesn't do any checking to verify that it supports the a requested encoding, instead set the curl option `CURLOPT_ENCODING` with an empty string indicating that curl should send an "Accept-Encoding" header containing only the encodings supported by curl. Reported-by: Anton Golubev <anton.golubev@gmail.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 22, 2018 at 11:42 UTC 1a53e692afd417897d76bff4ce54bc05a3a976b2
3 files changed +11 -6
http.c
+1 -1
@@ -1788,7 +1788,7 @@ static int http_request(const char *url,
1788
1789 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
1790 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
1791 - curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
1791 + curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
1792
1793 ret = run_one_slot(slot, &results);
1794
remote-curl.c
+1 -1
@@ -684,7 +684,7 @@ retry:
684 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
685 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
686 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
687 - curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
687 + curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
688
689 if (large_request) {
690 /* The request body is large and the size cannot be predicted.
t/t5551-http-fetch-smart.sh
+9 -4
@@ -26,14 +26,14 @@ setup_askpass_helper
26 cat >exp <<EOF
27 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
28 > Accept: */*
29 -> Accept-Encoding: gzip
29 +> Accept-Encoding: ENCODINGS
30 > Pragma: no-cache
31 < HTTP/1.1 200 OK
32 < Pragma: no-cache
33 < Cache-Control: no-cache, max-age=0, must-revalidate
34 < Content-Type: application/x-git-upload-pack-advertisement
35 > POST /smart/repo.git/git-upload-pack HTTP/1.1
36 -> Accept-Encoding: gzip
36 +> Accept-Encoding: ENCODINGS
37 > Content-Type: application/x-git-upload-pack-request
38 > Accept: application/x-git-upload-pack-result
39 > Content-Length: xxx
@@ -79,8 +79,13 @@ test_expect_success 'clone http repository' '
79 /^< Date: /d
80 /^< Content-Length: /d
81 /^< Transfer-Encoding: /d
82 - " >act &&
83 - test_cmp exp act
82 + " >actual &&
83 + sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
84 + actual >actual.smudged &&
85 + test_cmp exp actual.smudged &&
86 +
87 + grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
88 + test_line_count = 2 actual.gzip
89 '
90
91 test_expect_success 'fetch changes via http' '