Skip to content

Commit d01c76f

Browse files
bk2204gitster
authored andcommitted
http: use new headers for each object request
Currently we create one set of headers for all object requests and reuse it. However, we'll need to adjust the headers for authentication purposes in the future, so let's create a new set for each request so that we can adjust them if the authentication changes. Note that the cost of allocation here is tiny compared to the fact that we're making a network call, not to mention probably a full TLS connection, so this shouldn't have a significant impact on performance. Moreover, nobody who cares about performance is using the dumb HTTP protocol anyway, since it often makes huge numbers of requests compared to the smart protocol. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90765ea commit d01c76f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

http.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ static unsigned long empty_auth_useless =
128128
| CURLAUTH_DIGEST;
129129

130130
static struct curl_slist *pragma_header;
131-
static struct curl_slist *no_pragma_header;
132131
static struct string_list extra_http_headers = STRING_LIST_INIT_DUP;
133132

134133
static struct curl_slist *host_resolutions;
@@ -299,6 +298,11 @@ size_t fwrite_null(char *ptr UNUSED, size_t eltsize UNUSED, size_t nmemb,
299298
return nmemb;
300299
}
301300

301+
static struct curl_slist *object_request_headers(void)
302+
{
303+
return curl_slist_append(http_copy_default_headers(), "Pragma:");
304+
}
305+
302306
static void closedown_active_slot(struct active_request_slot *slot)
303307
{
304308
active_requests--;
@@ -1275,8 +1279,6 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
12751279

12761280
pragma_header = curl_slist_append(http_copy_default_headers(),
12771281
"Pragma: no-cache");
1278-
no_pragma_header = curl_slist_append(http_copy_default_headers(),
1279-
"Pragma:");
12801282

12811283
{
12821284
char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
@@ -1360,9 +1362,6 @@ void http_cleanup(void)
13601362
curl_slist_free_all(pragma_header);
13611363
pragma_header = NULL;
13621364

1363-
curl_slist_free_all(no_pragma_header);
1364-
no_pragma_header = NULL;
1365-
13661365
curl_slist_free_all(host_resolutions);
13671366
host_resolutions = NULL;
13681367

@@ -2370,6 +2369,7 @@ void release_http_pack_request(struct http_pack_request *preq)
23702369
}
23712370
preq->slot = NULL;
23722371
strbuf_release(&preq->tmpfile);
2372+
curl_slist_free_all(preq->headers);
23732373
free(preq->url);
23742374
free(preq);
23752375
}
@@ -2454,11 +2454,11 @@ struct http_pack_request *new_direct_http_pack_request(
24542454
}
24552455

24562456
preq->slot = get_active_slot();
2457+
preq->headers = object_request_headers();
24572458
curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEDATA, preq->packfile);
24582459
curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
24592460
curl_easy_setopt(preq->slot->curl, CURLOPT_URL, preq->url);
2460-
curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER,
2461-
no_pragma_header);
2461+
curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, preq->headers);
24622462

24632463
/*
24642464
* If there is data present from a previous transfer attempt,
@@ -2624,13 +2624,14 @@ struct http_object_request *new_http_object_request(const char *base_url,
26242624
}
26252625

26262626
freq->slot = get_active_slot();
2627+
freq->headers = object_request_headers();
26272628

26282629
curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEDATA, freq);
26292630
curl_easy_setopt(freq->slot->curl, CURLOPT_FAILONERROR, 0);
26302631
curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
26312632
curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr);
26322633
curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url);
2633-
curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
2634+
curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, freq->headers);
26342635

26352636
/*
26362637
* If we have successfully processed data from a previous fetch
@@ -2718,5 +2719,6 @@ void release_http_object_request(struct http_object_request *freq)
27182719
release_active_slot(freq->slot);
27192720
freq->slot = NULL;
27202721
}
2722+
curl_slist_free_all(freq->headers);
27212723
strbuf_release(&freq->tmpfile);
27222724
}

http.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ struct http_pack_request {
196196
FILE *packfile;
197197
struct strbuf tmpfile;
198198
struct active_request_slot *slot;
199+
struct curl_slist *headers;
199200
};
200201

201202
struct http_pack_request *new_http_pack_request(
@@ -229,6 +230,7 @@ struct http_object_request {
229230
int zret;
230231
int rename;
231232
struct active_request_slot *slot;
233+
struct curl_slist *headers;
232234
};
233235

234236
struct http_object_request *new_http_object_request(

0 commit comments

Comments
 (0)