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

NAME

6       CURLOPT_ACCEPT_ENCODING - enables automatic decompression of HTTP down‐
7       loads
8

SYNOPSIS

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

DESCRIPTION

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

DEFAULT

66       NULL
67

PROTOCOLS

69       HTTP
70

EXAMPLE

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

AVAILABILITY

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

RETURN VALUE

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

SEE ALSO

96       CURLOPT_TRANSFER_ENCODING(3), CURLOPT_HTTPHEADER(3),  CURLOPT_HTTP_CON‐
97       TENT_DECODING(3),
98
99
100
101libcurl 7.76.1                 November 04, 2020    CURLOPT_ACCEPT_ENCODING(3)
Impressum