xref: /curl/docs/libcurl/opts/CURLOPT_HEADER.md (revision e3fe0200)
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)
16---
17
18# NAME
19
20CURLOPT_HEADER - pass headers to the data stream
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HEADER, long onoff);
28~~~
29
30# DESCRIPTION
31
32Pass the long value *onoff* set to 1 to ask libcurl to include the headers
33in the write callback (CURLOPT_WRITEFUNCTION(3)). This option is
34relevant for protocols that actually have headers or other meta-data (like
35HTTP and FTP).
36
37When asking to get the headers passed to the same callback as the body, it is
38not possible to accurately separate them again without detailed knowledge
39about the protocol in use.
40
41Further: the CURLOPT_WRITEFUNCTION(3) callback is limited to only ever
42get a maximum of *CURL_MAX_WRITE_SIZE* bytes passed to it (16KB), while a
43header can be longer and the CURLOPT_HEADERFUNCTION(3) supports getting
44called with headers up to *CURL_MAX_HTTP_HEADER* bytes big (100KB).
45
46It is often better to use CURLOPT_HEADERFUNCTION(3) to get the header
47data separately.
48
49While named confusingly similar, CURLOPT_HTTPHEADER(3) is used to set
50custom HTTP headers!
51
52# DEFAULT
53
540
55
56# EXAMPLE
57
58~~~c
59int main(void)
60{
61  CURL *curl = curl_easy_init();
62  if(curl) {
63    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
64
65    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
66
67    curl_easy_perform(curl);
68  }
69}
70~~~
71
72# AVAILABILITY
73
74Provided in all libcurl versions.
75
76# RETURN VALUE
77
78Returns CURLE_OK.
79