Artifactspublic-v0

curl

master
ply4 git calls145 ms290 KiB2 cachedprotocol v2
215 lines7.2 KiBRaw

NAME

CURLOPT_HTTPHEADER - set of HTTP headers

SYNOPSIS

c
#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPHEADER,
                          struct curl_slist *headers);

DESCRIPTION

Pass a pointer to a linked list of HTTP headers to pass to the server and/or proxy in your HTTP request. The same list can be used for both host and proxy requests.

When used within an IMAP or SMTP request to upload a MIME mail, the given header list establishes the document-level MIME headers to prepend to the uploaded document described by CURLOPT_MIMEPOST(3). This does not affect raw mail uploads.

When used with HTTP, this option can add new headers, replace internal headers and remove internal headers.

The linked list should be a valid list of struct curl_slist entries properly filled in. Use curl_slist_append(3) to create the list and curl_slist_free_all(3) to free it again after use.

If you provide a header that is otherwise generated and used by libcurl internally, your header alternative is used instead. If you provide a header without content (no data on the right side of the colon) as in Accept:, the internally used header is removed. To forcibly add a header without content (nothing after the colon), use the form name; (using a trailing semicolon).

There are exceptions when suppressing headers. The Connection: header in HTTP/1.1 cannot be overridden. You can provide values for it, but should a request require specific ones, they are always added to your own.

The headers included in the linked list must not be CRLF-terminated, since libcurl adds CRLF after each header item itself. Failure to comply with this might result in strange behavior. libcurl passes on the verbatim strings you give it, without any filter or other safe guards. That includes white space and control characters.

The first line in an HTTP request (containing the method, usually a GET or POST) is not a header and cannot be replaced using this option. Only the lines following the request-line are headers. Adding this method line in this list of headers only causes your request to send an invalid header. Use CURLOPT_CUSTOMREQUEST(3) to change the method.

When this option is passed to curl_easy_setopt(3), libcurl does not copy the entire list so you must keep it around until you no longer use this handle for a transfer before you call curl_slist_free_all(3) on the list.

Using this option multiple times makes the last set list override the previous ones. Set it to NULL to disable its use again.

The most commonly replaced HTTP headers have "shortcuts" in the options CURLOPT_COOKIE(3), CURLOPT_USERAGENT(3) and CURLOPT_REFERER(3). We recommend using those.

There is an alternative option that sets or replaces headers only for requests that are sent with CONNECT to a proxy: CURLOPT_PROXYHEADER(3). Use CURLOPT_HEADEROPT(3) to control the behavior.

SPECIFIC HTTP HEADERS

Setting some specific headers causes libcurl to act differently.

Host:

The specified hostname is used for cookie matching if the cookie engine is also enabled for this transfer. If the request is done over HTTP/2 or HTTP/3, the custom hostname is instead used in the ":authority" header field and Host: is not sent at all over the wire.

Transfer-Encoding: chunked

Tells libcurl the upload is to be done using this chunked encoding instead of providing the Content-Length: field in the request.

Authorization:

Custom Authorization: headers may interfere with and cause unintended side-effects when combined with authentication set with CURLOPT_HTTPAUTH(3).

Proxy-Authorization:

Custom Proxy-Authorization: headers may interfere with and cause unintended side-effects when combined with authentication set with CURLOPT_PROXYAUTH(3).

SPECIFIC MIME HEADERS

When used to build a MIME email for IMAP or SMTP, the following document-level headers can be set to override libcurl-generated values:

Mime-Version:

Tells the parser at the receiving site how to interpret the MIME framing. It defaults to "1.0" and should normally not be altered.

Content-Type:

Indicates the document's global structure type. By default, libcurl sets it to "multipart/mixed", describing a document made of independent parts. When a MIME mail is only composed of alternative representations of the same data (i.e.: HTML and plain text), this header must be set to "multipart/alternative". In all cases the value must be of the form "multipart/*" to respect the document structure and may not include the "boundary=" parameter.

Other specific headers that do not have a libcurl default value but are strongly desired by mail delivery and user agents should also be included. These are From:, To:, Date: and Subject: among others and their presence and value is generally checked by anti-spam utilities.

SECURITY CONCERNS

By default, this option makes libcurl send the given headers in all HTTP requests done by this handle. You should therefore use this option with caution if you for example connect to the remote site using a proxy and a CONNECT request, you should to consider if that proxy is supposed to also get the headers. They may be private or otherwise sensitive to leak.

Use CURLOPT_HEADEROPT(3) to make the headers only get sent to where you intend them to get sent.

Custom headers are sent in all requests done by the easy handle, which implies that if you tell libcurl to follow redirects (CURLOPT_FOLLOWLOCATION(3)), the same set of custom headers is sent in the subsequent request. Redirects can of course go to other hosts and thus those servers get all the contents of your custom headers too.

Starting in 7.58.0, libcurl specifically prevents "Authorization:" headers from being sent to other hosts than the first used one, unless specifically permitted with the CURLOPT_UNRESTRICTED_AUTH(3) option.

Starting in 7.64.0, libcurl specifically prevents "Cookie:" headers from being sent to other hosts than the first used one, unless specifically permitted with the CURLOPT_UNRESTRICTED_AUTH(3) option.

DEFAULT

NULL

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  CURL *curl = curl_easy_init();

  struct curl_slist *list = NULL;

  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

    /* add this header */
    list = curl_slist_append(list, "Shoesize: 10");

    /* remove this header */
    list = curl_slist_append(list, "Accept:");

    /* change this header */
    list = curl_slist_append(list, "Host: example.net");

    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);

    result = curl_easy_perform(curl);

    curl_slist_free_all(list); /* free the list */
    curl_easy_cleanup(curl);
  }
}

HISTORY

Use for MIME mail added in 7.56.0.

%AVAILABILITY%

RETURN VALUE

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3).

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HTTPHEADER
5Section: 3
6Source: libcurl
7Protocol:
8 - HTTP
9 - SMTP
10 - IMAP
11See-also:
12 - CURLOPT_CUSTOMREQUEST (3)
13 - CURLOPT_HEADER (3)
14 - CURLOPT_HEADEROPT (3)
15 - CURLOPT_MIMEPOST (3)
16 - CURLOPT_PROXYHEADER (3)
17 - curl_mime_init (3)
18Added-in: 7.1
19---
21# NAME
23CURLOPT_HTTPHEADER - set of HTTP headers
25# SYNOPSIS
27~~~c
28#include <curl/curl.h>
30CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPHEADER,
31 struct curl_slist *headers);
32~~~
34# DESCRIPTION
36Pass a pointer to a linked list of HTTP headers to pass to the server and/or
37proxy in your HTTP request. The same list can be used for both host and proxy
38requests.
40When used within an IMAP or SMTP request to upload a MIME mail, the given
41header list establishes the document-level MIME headers to prepend to the
42uploaded document described by CURLOPT_MIMEPOST(3). This does not affect raw
43mail uploads.
45When used with HTTP, this option can add new headers, replace internal headers
46and remove internal headers.
48The linked list should be a valid list of **struct curl_slist** entries
49properly filled in. Use curl_slist_append(3) to create the list and
50curl_slist_free_all(3) to free it again after use.
52If you provide a header that is otherwise generated and used by libcurl
53internally, your header alternative is used instead. If you provide a header
54without content (no data on the right side of the colon) as in `Accept:`, the
55internally used header is removed. To forcibly add a header without content
56(nothing after the colon), use the form `name;` (using a trailing semicolon).
58There are exceptions when suppressing headers. The `Connection:` header in
59HTTP/1.1 cannot be overridden. You can provide values for it, but should a
60request require specific ones, they are always added to your own.
62The headers included in the linked list **must not** be CRLF-terminated, since
63libcurl adds CRLF after each header item itself. Failure to comply with this
64might result in strange behavior. libcurl passes on the verbatim strings you
65give it, without any filter or other safe guards. That includes white space
66and control characters.
68The first line in an HTTP request (containing the method, usually a GET or
69POST) is not a header and cannot be replaced using this option. Only the lines
70following the request-line are headers. Adding this method line in this list
71of headers only causes your request to send an invalid header. Use
72CURLOPT_CUSTOMREQUEST(3) to change the method.
74When this option is passed to curl_easy_setopt(3), libcurl does not copy the
75entire list so you **must** keep it around until you no longer use this
76*handle* for a transfer before you call curl_slist_free_all(3) on the list.
78Using this option multiple times makes the last set list override the previous
79ones. Set it to NULL to disable its use again.
81The most commonly replaced HTTP headers have "shortcuts" in the options
82CURLOPT_COOKIE(3), CURLOPT_USERAGENT(3) and CURLOPT_REFERER(3). We recommend
83using those.
85There is an alternative option that sets or replaces headers only for requests
86that are sent with CONNECT to a proxy: CURLOPT_PROXYHEADER(3). Use
87CURLOPT_HEADEROPT(3) to control the behavior.
89# SPECIFIC HTTP HEADERS
91Setting some specific headers causes libcurl to act differently.
93## Host:
95The specified hostname is used for cookie matching if the cookie engine is
96also enabled for this transfer. If the request is done over HTTP/2 or HTTP/3,
97the custom hostname is instead used in the ":authority" header field and
98Host: is not sent at all over the wire.
100## Transfer-Encoding: chunked
102Tells libcurl the upload is to be done using this chunked encoding instead of
103providing the Content-Length: field in the request.
105## Authorization:
107Custom `Authorization:` headers may interfere with and cause unintended
108side-effects when combined with authentication set with CURLOPT_HTTPAUTH(3).
110## Proxy-Authorization:
112Custom `Proxy-Authorization:` headers may interfere with and cause unintended
113side-effects when combined with authentication set with CURLOPT_PROXYAUTH(3).
115# SPECIFIC MIME HEADERS
117When used to build a MIME email for IMAP or SMTP, the following document-level
118headers can be set to override libcurl-generated values:
120## Mime-Version:
122Tells the parser at the receiving site how to interpret the MIME framing.
123It defaults to "1.0" and should normally not be altered.
125## Content-Type:
127Indicates the document's global structure type. By default, libcurl sets it
128to "multipart/mixed", describing a document made of independent parts. When a
129MIME mail is only composed of alternative representations of the same data
130(i.e.: HTML and plain text), this header must be set to "multipart/alternative".
131In all cases the value must be of the form "multipart/*" to respect the
132document structure and may not include the "boundary=" parameter.
134##
136Other specific headers that do not have a libcurl default value but are
137strongly desired by mail delivery and user agents should also be included.
138These are `From:`, `To:`, `Date:` and `Subject:` among others and their
139presence and value is generally checked by anti-spam utilities.
141# SECURITY CONCERNS
143By default, this option makes libcurl send the given headers in all HTTP
144requests done by this handle. You should therefore use this option with
145caution if you for example connect to the remote site using a proxy and a
146CONNECT request, you should to consider if that proxy is supposed to also get
147the headers. They may be private or otherwise sensitive to leak.
149Use CURLOPT_HEADEROPT(3) to make the headers only get sent to where you
150intend them to get sent.
152Custom headers are sent in all requests done by the easy handle, which implies
153that if you tell libcurl to follow redirects
154(CURLOPT_FOLLOWLOCATION(3)), the same set of custom headers is sent in
155the subsequent request. Redirects can of course go to other hosts and thus
156those servers get all the contents of your custom headers too.
158Starting in 7.58.0, libcurl specifically prevents "Authorization:" headers
159from being sent to other hosts than the first used one, unless specifically
160permitted with the CURLOPT_UNRESTRICTED_AUTH(3) option.
162Starting in 7.64.0, libcurl specifically prevents "Cookie:" headers from being
163sent to other hosts than the first used one, unless specifically permitted
164with the CURLOPT_UNRESTRICTED_AUTH(3) option.
166# DEFAULT
168NULL
170# %PROTOCOLS%
172# EXAMPLE
174~~~c
175int main(void)
177 CURL *curl = curl_easy_init();
179 struct curl_slist *list = NULL;
181 if(curl) {
182 CURLcode result;
183 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
185 /* add this header */
186 list = curl_slist_append(list, "Shoesize: 10");
188 /* remove this header */
189 list = curl_slist_append(list, "Accept:");
191 /* change this header */
192 list = curl_slist_append(list, "Host: example.net");
194 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
196 result = curl_easy_perform(curl);
198 curl_slist_free_all(list); /* free the list */
199 curl_easy_cleanup(curl);
200 }
202~~~
204# HISTORY
206Use for MIME mail added in 7.56.0.
208# %AVAILABILITY%
210# RETURN VALUE
212curl_easy_setopt(3) returns a CURLcode indicating success or error.
214CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
215libcurl-errors(3).
Diagnostics4 git calls · 145 ms
CallStatusSizeTime0145 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.2 KiB140 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=140
git.response.bytes=3316
git.response.cache=MISS
git.response.duration_ms=140
git.fetch.wants=34a864adb11e109ebb376758e70241cf8d1b5214
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3316
git.pkt.payload.max=3295
git.sideband.band1.bytes=3294
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e313817d273e6e
Request
2e53d71d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format