Skip to content

Commit aa90b96

Browse files
spearcegitster
authored andcommitted
Enable info/refs gzip decompression in HTTP client
Some HTTP servers try to use gzip compression on the /info/refs request to save transfer bandwidth. Repositories with many tags may find the /info/refs request can be gzipped to be 50% of the original size due to the few but often repeated bytes used (hex SHA-1 and commonly digits in tag names). For most HTTP requests enable "Accept-Encoding: gzip" ensuring the /info/refs payload can use this encoding format. Only request gzip encoding from servers. Although deflate is supported by libcurl, most servers have standardized on gzip encoding for compression as that is what most browsers support. Asking for deflate increases request sizes by a few bytes, but is unlikely to ever be used by a server. Disable the Accept-Encoding header on probe RPCs as response bodies are supposed to be exactly 4 bytes long, "0000". The HTTP headers requesting and indicating compression use more space than the data transferred in the body. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25ae7cf commit aa90b96

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ static int http_request(const char *url, void *result, int target, int options)
818818

819819
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
820820
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
821+
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
821822

822823
if (start_active_slot(slot)) {
823824
run_active_slot(slot);

remote-curl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int probe_rpc(struct rpc_state *rpc)
393393
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
394394
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
395395
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
396-
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
396+
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
397397
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
398398
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
399399
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
@@ -449,7 +449,7 @@ static int post_rpc(struct rpc_state *rpc)
449449
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
450450
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
451451
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
452-
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
452+
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
453453

454454
headers = curl_slist_append(headers, rpc->hdr_content_type);
455455
headers = curl_slist_append(headers, rpc->hdr_accept);

t/t5551-http-fetch.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ setup_askpass_helper
3232
cat >exp <<EOF
3333
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
3434
> Accept: */*
35+
> Accept-Encoding: gzip
3536
> Pragma: no-cache
3637
< HTTP/1.1 200 OK
3738
< Pragma: no-cache
3839
< Cache-Control: no-cache, max-age=0, must-revalidate
3940
< Content-Type: application/x-git-upload-pack-advertisement
4041
> POST /smart/repo.git/git-upload-pack HTTP/1.1
41-
> Accept-Encoding: deflate, gzip
42+
> Accept-Encoding: gzip
4243
> Content-Type: application/x-git-upload-pack-request
4344
> Accept: application/x-git-upload-pack-result
4445
> Content-Length: xxx

0 commit comments

Comments
 (0)