Skip to content

Commit 1a53e69

Browse files
bmwillgitster
authored andcommitted
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 aa90b96 (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 <[email protected]> Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccdcbd5 commit 1a53e69

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ static int http_request(const char *url,
17881788

17891789
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
17901790
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, "");
17921792

17931793
ret = run_one_slot(slot, &results);
17941794

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static int post_rpc(struct rpc_state *rpc)
684684
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
685685
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
686686
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, "");
688688

689689
if (large_request) {
690690
/* The request body is large and the size cannot be predicted.

t/t5551-http-fetch-smart.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ setup_askpass_helper
2626
cat >exp <<EOF
2727
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
2828
> Accept: */*
29-
> Accept-Encoding: gzip
29+
> Accept-Encoding: ENCODINGS
3030
> Pragma: no-cache
3131
< HTTP/1.1 200 OK
3232
< Pragma: no-cache
3333
< Cache-Control: no-cache, max-age=0, must-revalidate
3434
< Content-Type: application/x-git-upload-pack-advertisement
3535
> POST /smart/repo.git/git-upload-pack HTTP/1.1
36-
> Accept-Encoding: gzip
36+
> Accept-Encoding: ENCODINGS
3737
> Content-Type: application/x-git-upload-pack-request
3838
> Accept: application/x-git-upload-pack-result
3939
> Content-Length: xxx
@@ -79,8 +79,13 @@ test_expect_success 'clone http repository' '
7979
/^< Date: /d
8080
/^< Content-Length: /d
8181
/^< 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
8489
'
8590

8691
test_expect_success 'fetch changes via http' '

0 commit comments

Comments
 (0)