xref: /curl/docs/libcurl/opts/CURLOPT_HEADEROPT.md (revision 3040971d)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HEADEROPT
5Section: 3
6Source: libcurl
7Protocol:
8  - HTTP
9See-also:
10  - CURLOPT_HTTPHEADER (3)
11  - CURLOPT_PROXYHEADER (3)
12Added-in: 7.37.0
13---
14
15# NAME
16
17CURLOPT_HEADEROPT - send HTTP headers to both proxy and host or separately
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADEROPT, long bitmask);
25~~~
26
27# DESCRIPTION
28
29Pass a long that is a bitmask of options of how to deal with headers. The two
30mutually exclusive options are:
31
32**CURLHEADER_UNIFIED** - the headers specified in
33CURLOPT_HTTPHEADER(3) are used in requests both to servers and
34proxies. With this option enabled, CURLOPT_PROXYHEADER(3) does not have
35any effect.
36
37**CURLHEADER_SEPARATE** - makes CURLOPT_HTTPHEADER(3) headers only get
38sent to a server and not to a proxy. Proxy headers must be set with
39CURLOPT_PROXYHEADER(3) to get used. Note that if a non-CONNECT request
40is sent to a proxy, libcurl sends both server headers and proxy headers. When
41doing CONNECT, libcurl sends CURLOPT_PROXYHEADER(3) headers only to the
42proxy and then CURLOPT_HTTPHEADER(3) headers only to the server.
43
44# DEFAULT
45
46CURLHEADER_SEPARATE (changed in 7.42.1, used CURLHEADER_UNIFIED before then)
47
48# %PROTOCOLS%
49
50# EXAMPLE
51
52~~~c
53int main(void)
54{
55  CURL *curl = curl_easy_init();
56  if(curl) {
57    CURLcode ret;
58    struct curl_slist *list;
59    list = curl_slist_append(NULL, "Shoesize: 10");
60    list = curl_slist_append(list, "Accept:");
61    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
62    curl_easy_setopt(curl, CURLOPT_PROXY, "http://localhost:8080");
63    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
64
65    /* HTTPS over a proxy makes a separate CONNECT to the proxy, so tell
66       libcurl to not send the custom headers to the proxy. Keep them
67       separate. */
68    curl_easy_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
69    ret = curl_easy_perform(curl);
70    curl_slist_free_all(list);
71    curl_easy_cleanup(curl);
72  }
73}
74~~~
75
76# %AVAILABILITY%
77
78# RETURN VALUE
79
80Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
81