Skip to content

Commit

Permalink
http: allow providing extra headers for http requests
Browse files Browse the repository at this point in the history
Add a way for callers to request that extra headers be included when
making http requests.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bmwill authored and gitster committed Mar 15, 2018
1 parent 49e85e9 commit 8ff14ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions http.c
Expand Up @@ -1723,6 +1723,14 @@ static int http_request(const char *url,

headers = curl_slist_append(headers, buf.buf);

/* Add additional headers here */
if (options && options->extra_headers) {
const struct string_list_item *item;
for_each_string_list_item(item, options->extra_headers) {
headers = curl_slist_append(headers, item->string);
}
}

curl_easy_setopt(slot->curl, CURLOPT_URL, url);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
Expand Down
7 changes: 7 additions & 0 deletions http.h
Expand Up @@ -172,6 +172,13 @@ struct http_get_options {
* for details.
*/
struct strbuf *base_url;

/*
* If not NULL, contains additional HTTP headers to be sent with the
* request. The strings in the list must not be freed until after the
* request has completed.
*/
struct string_list *extra_headers;
};

/* Return values for http_get_*() */
Expand Down

0 comments on commit 8ff14ed

Please sign in to comment.