[PATCH] git-http-fetch: Allow caching of retrieved objects by proxy servers
By default the curl library adds "Pragma: no-cache" header to all requests, which disables caching by proxy servers. However, most files in a GIT repository are immutable, and caching them is safe and could be useful. This patch removes the "Pragma: no-cache" header from requests for all files except the pack list (objects/info/packs) and references (refs/*), which are really mutable and should not be cached. Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Junio C Hamano <junkio@cox.net> (cherry picked from 3b2a4c46fd5093ec79fb60e1b14b8d4a58c74612 commit)
Sergey Vlasov committed
Sep 13, 2005 at 19:38 UTC
1db69b571c9eaab73a7b21303bfedda5fb5f31ce
1 file changed
+8
http-fetch.c
+8
@@ -14,6 +14,7 @@
14
#endif
15
16
static CURL *curl;
17
+static struct curl_slist *no_pragma_header;
18
19
static char *base;
20
@@ -102,6 +103,7 @@ static int fetch_index(unsigned char *sha1)
103
curl_easy_setopt(curl, CURLOPT_FILE, indexfile);
104
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
105
curl_easy_setopt(curl, CURLOPT_URL, url);
106
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
107
108
if (curl_easy_perform(curl)) {
109
fclose(indexfile);
@@ -152,6 +154,7 @@ static int fetch_indices(void)
154
curl_easy_setopt(curl, CURLOPT_FILE, &buffer);
155
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
156
curl_easy_setopt(curl, CURLOPT_URL, url);
157
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
158
159
if (curl_easy_perform(curl)) {
160
return error("Unable to get pack index %s", url);
@@ -215,6 +218,7 @@ static int fetch_pack(unsigned char *sha1)
218
curl_easy_setopt(curl, CURLOPT_FILE, packfile);
219
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
220
curl_easy_setopt(curl, CURLOPT_URL, url);
221
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
222
223
if (curl_easy_perform(curl)) {
224
fclose(packfile);
@@ -255,6 +259,7 @@ int fetch(unsigned char *sha1)
259
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
260
curl_easy_setopt(curl, CURLOPT_FILE, NULL);
261
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
262
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
263
264
url = xmalloc(strlen(base) + 50);
265
strcpy(url, base);
@@ -303,6 +308,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
308
309
curl_easy_setopt(curl, CURLOPT_FILE, &buffer);
310
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
311
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
312
313
url = xmalloc(strlen(base) + 6 + strlen(ref));
314
strcpy(url, base);
@@ -354,6 +360,7 @@ int main(int argc, char **argv)
360
curl_global_init(CURL_GLOBAL_ALL);
361
362
curl = curl_easy_init();
363
+ no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
364
365
curl_ssl_verify = getenv("GIT_SSL_NO_VERIFY") ? 0 : 1;
366
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
@@ -366,6 +373,7 @@ int main(int argc, char **argv)
373
if (pull(commit_id))
374
return 1;
375
376
+ curl_slist_free_all(no_pragma_header);
377
curl_global_cleanup();
378
return 0;
379
}