CURLOPT_HEADEROPT.md (2263B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_HEADEROPT 5 Section: 3 6 Source: libcurl 7 Protocol: 8 - HTTP 9 See-also: 10 - CURLOPT_HTTPHEADER (3) 11 - CURLOPT_PROXYHEADER (3) 12 Added-in: 7.37.0 13 --- 14 15 # NAME 16 17 CURLOPT_HEADEROPT - send HTTP headers to both proxy and host or separately 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADEROPT, long bitmask); 25 ~~~ 26 27 # DESCRIPTION 28 29 Pass a long that is a bitmask of options of how to deal with headers. The two 30 mutually exclusive options are: 31 32 **CURLHEADER_UNIFIED** - the headers specified in 33 CURLOPT_HTTPHEADER(3) are used in requests both to servers and 34 proxies. With this option enabled, CURLOPT_PROXYHEADER(3) does not have 35 any effect. 36 37 **CURLHEADER_SEPARATE** - makes CURLOPT_HTTPHEADER(3) headers only get 38 sent to a server and not to a proxy. Proxy headers must be set with 39 CURLOPT_PROXYHEADER(3) to get used. Note that if a non-CONNECT request 40 is sent to a proxy, libcurl sends both server headers and proxy headers. When 41 doing CONNECT, libcurl sends CURLOPT_PROXYHEADER(3) headers only to the 42 proxy and then CURLOPT_HTTPHEADER(3) headers only to the server. 43 44 # DEFAULT 45 46 CURLHEADER_SEPARATE (changed in 7.42.1, used CURLHEADER_UNIFIED before then) 47 48 # %PROTOCOLS% 49 50 # EXAMPLE 51 52 ~~~c 53 int 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, (long)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 80 curl_easy_setopt(3) returns a CURLcode indicating success or error. 81 82 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 83 libcurl-errors(3).