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 <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 15, 2018 at 10:31 UTC 8ff14ed4127decbee3116aba59d7f8f897c4fe3b
2 files changed +15
http.c
+8
@@ -1723,6 +1723,14 @@ static int http_request(const char *url,
1723
1724 headers = curl_slist_append(headers, buf.buf);
1725
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 +
1734 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
1735 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
1736 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
http.h
+7
@@ -172,6 +172,13 @@ struct http_get_options {
172 * for details.
173 */
174 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;
182 };
183
184 /* Return values for http_get_*() */