xref: /curl/docs/libcurl/opts/CURLOPT_HEADER.md (revision 3040971d)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HEADER
5Section: 3
6Source: libcurl
7Protocol:
8  - HTTP
9  - FTP
10  - IMAP
11  - POP3
12  - SMTP
13See-also:
14  - CURLOPT_HEADERFUNCTION (3)
15  - CURLOPT_HTTPHEADER (3)
16Added-in: 7.1
17---
18
19# NAME
20
21CURLOPT_HEADER - pass headers to the data stream
22
23# SYNOPSIS
24
25~~~c
26#include <curl/curl.h>
27
28CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADER, long onoff);
29~~~
30
31# DESCRIPTION
32
33Pass the long value *onoff* set to 1 to ask libcurl to include the headers
34in the write callback (CURLOPT_WRITEFUNCTION(3)). This option is
35relevant for protocols that actually have headers or other meta-data (like
36HTTP and FTP).
37
38When asking to get the headers passed to the same callback as the body, it is
39not possible to accurately separate them again without detailed knowledge
40about the protocol in use.
41
42Further: the CURLOPT_WRITEFUNCTION(3) callback is limited to only ever
43get a maximum of *CURL_MAX_WRITE_SIZE* bytes passed to it (16KB), while a
44header can be longer and the CURLOPT_HEADERFUNCTION(3) supports getting
45called with headers up to *CURL_MAX_HTTP_HEADER* bytes big (100KB).
46
47It is often better to use CURLOPT_HEADERFUNCTION(3) to get the header
48data separately.
49
50While named confusingly similar, CURLOPT_HTTPHEADER(3) is used to set
51custom HTTP headers.
52
53# DEFAULT
54
550
56
57# %PROTOCOLS%
58
59# EXAMPLE
60
61~~~c
62int main(void)
63{
64  CURL *curl = curl_easy_init();
65  if(curl) {
66    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
67
68    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
69
70    curl_easy_perform(curl);
71  }
72}
73~~~
74
75# %AVAILABILITY%
76
77# RETURN VALUE
78
79Returns CURLE_OK.
80