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
12       *enc);
13

DESCRIPTION

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

DEFAULT

65       NULL
66

PROTOCOLS

68       HTTP
69

EXAMPLE

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

AVAILABILITY

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

RETURN VALUE

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

SEE ALSO

95       CURLOPT_TRANSFER_ENCODING(3),  CURLOPT_HTTPHEADER(3), CURLOPT_HTTP_CON‐
96       TENT_DECODING(3),
97
98
99
100libcurl 7.79.1                September 08, 2021    CURLOPT_ACCEPT_ENCODING(3)
Impressum