Skip to content

Commit 8ff14ed

Browse files
bmwillgitster
authored andcommitted
http: allow providing extra headers for http requests
Add a way for callers to request that extra headers be included when making http requests. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49e85e9 commit 8ff14ed

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

http.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,14 @@ static int http_request(const char *url,
17231723

17241724
headers = curl_slist_append(headers, buf.buf);
17251725

1726+
/* Add additional headers here */
1727+
if (options && options->extra_headers) {
1728+
const struct string_list_item *item;
1729+
for_each_string_list_item(item, options->extra_headers) {
1730+
headers = curl_slist_append(headers, item->string);
1731+
}
1732+
}
1733+
17261734
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
17271735
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
17281736
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");

http.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ struct http_get_options {
172172
* for details.
173173
*/
174174
struct strbuf *base_url;
175+
176+
/*
177+
* If not NULL, contains additional HTTP headers to be sent with the
178+
* request. The strings in the list must not be freed until after the
179+
* request has completed.
180+
*/
181+
struct string_list *extra_headers;
175182
};
176183

177184
/* Return values for http_get_*() */

0 commit comments

Comments
 (0)