1CURLOPT_ACCEPT_ENCODING(3) curl_easy_setopt options CURLOPT_ACCEPT_ENCODING(3)
2
3
4

NAME

6       CURLOPT_ACCEPT_ENCODING - automatic decompression of HTTP downloads
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc);
12

DESCRIPTION

14       Pass a char * argument specifying what encoding you would like.
15
16       Sets  the  contents  of the Accept-Encoding: header sent in an HTTP re‐
17       quest, and enables decoding of  a  response  when  a  Content-Encoding:
18       header is received.
19
20       libcurl potentially supports several different compressed encodings de‐
21       pending on what support that has been built-in.
22
23       To aid applications not having to bother about what specific algorithms
24       this  particular  libcurl  build supports, libcurl allows a zero-length
25       string to be set ("") to ask for an Accept-Encoding: header to be  used
26       that contains all built-in supported encodings.
27
28       Alternatively,  you  can specify exactly the encoding or list of encod‐
29       ings you want in the response. Four encodings are supported:  identity,
30       meaning  non-compressed,  deflate which requests the server to compress
31       its response using the zlib algorithm, gzip which requests the gzip al‐
32       gorithm, (since curl 7.57.0) br which is brotli and (since curl 7.72.0)
33       zstd which is zstd.  Provide them in the string  as  a  comma-separated
34       list of accepted encodings, like:
35
36         "br, gzip, deflate".
37
38       Set  CURLOPT_ACCEPT_ENCODING(3) to NULL to explicitly disable it, which
39       makes libcurl not send an Accept-Encoding: header  and  not  decompress
40       received contents automatically.
41
42       You  can  also  opt to just include the Accept-Encoding: header in your
43       request with CURLOPT_HTTPHEADER(3) but then there will be no  automatic
44       decompressing when receiving data.
45
46       This is a request, not an order; the server may or may not do it.  This
47       option must be set (to any non-NULL value) or else any unsolicited  en‐
48       coding done by the server is ignored.
49
50       Servers  might respond with Content-Encoding even without getting a Ac‐
51       cept-Encoding: in the request. Servers might respond with  a  different
52       Content-Encoding than what was asked for in the request.
53
54       The  Content-Length: servers send for a compressed response is supposed
55       to indicate the length of the compressed content so when auto  decoding
56       is  enabled  it  may  not  match the sum of bytes reported by the write
57       callbacks (although, sending the length of the  non-compressed  content
58       is a common server mistake).
59
60       The  application  does not have to keep the string around after setting
61       this option.
62

DEFAULT

64       NULL
65

PROTOCOLS

67       HTTP
68

EXAMPLE

70       CURL *curl = curl_easy_init();
71       if(curl) {
72         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
73
74         /* enable all supported built-in compressions */
75         curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
76
77         /* Perform the request */
78         curl_easy_perform(curl);
79       }
80

AVAILABILITY

82       This option was called CURLOPT_ENCODING before 7.21.6
83
84       The specific libcurl you are using must have been built with zlib to be
85       able  to decompress gzip and deflate responses, with the brotli library
86       to decompress brotli responses and with the zstd library to  decompress
87       zstd responses.
88

RETURN VALUE

90       Returns  CURLE_OK  if  the option is supported, CURLE_UNKNOWN_OPTION if
91       not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space.
92

SEE ALSO

94       CURLOPT_TRANSFER_ENCODING(3), CURLOPT_HTTPHEADER(3),  CURLOPT_HTTP_CON‐
95       TENT_DECODING(3),
96
97
98
99libcurl 7.85.0                   May 17, 2022       CURLOPT_ACCEPT_ENCODING(3)
Impressum