mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
http: support sending custom HTTP headers
We introduce a way to send custom HTTP headers with all requests. This allows us, for example, to send an extra token from build agents for temporary access to private repositories. (This is the use case that triggered this patch.) This feature can be used like this: git -c http.extraheader='Secret: sssh!' fetch $URL $REF Note that `curl_easy_setopt(..., CURLOPT_HTTPHEADER, ...)` takes only a single list, overriding any previous call. This means we have to collect _all_ of the headers we want to use into a single list, and feed it to cURL in one shot. Since we already unconditionally set a "pragma" header when initializing the curl handles, we can add our new headers to that list. For callers which override the default header list (like probe_rpc), we provide `http_copy_default_headers()` so they can do the same trick. Big thanks to Jeff King and Junio Hamano for their outstanding help and patient reviews. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
90f7b16b3a
commit
8cb01e2fd3
@@ -474,7 +474,7 @@ static int run_slot(struct active_request_slot *slot,
|
||||
static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
|
||||
{
|
||||
struct active_request_slot *slot;
|
||||
struct curl_slist *headers = NULL;
|
||||
struct curl_slist *headers = http_copy_default_headers();
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
int err;
|
||||
|
||||
@@ -503,7 +503,7 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
|
||||
static int post_rpc(struct rpc_state *rpc)
|
||||
{
|
||||
struct active_request_slot *slot;
|
||||
struct curl_slist *headers = NULL;
|
||||
struct curl_slist *headers = http_copy_default_headers();
|
||||
int use_gzip = rpc->gzip_request;
|
||||
char *gzip_body = NULL;
|
||||
size_t gzip_size = 0;
|
||||
|
||||
Reference in New Issue
Block a user