1CURLOPT_ACCEPT_ENCODING(3) libcurl CURLOPT_ACCEPT_ENCODING(3)
2
3
4
6 CURLOPT_ACCEPT_ENCODING - automatic decompression of HTTP downloads
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc);
12
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. The following encodings are supported:
30 identity, meaning non-compressed, deflate which requests the server to
31 compress its response using the zlib algorithm, gzip which requests the
32 gzip algorithm, (since curl 7.57.0) br which is brotli and (since curl
33 7.72.0) zstd which is zstd. Provide them in the string as a comma-sepa‐
34 rated list of accepted encodings, like: "br, gzip, deflate".
35
36 Set CURLOPT_ACCEPT_ENCODING(3) to NULL to explicitly disable it, which
37 makes libcurl not send an Accept-Encoding: header and not decompress
38 received contents automatically.
39
40 You can also opt to just include the Accept-Encoding: header in your
41 request with CURLOPT_HTTPHEADER(3) but then there will be no automatic
42 decompressing when receiving data.
43
44 This is a request, not an order; the server may or may not do it. This
45 option must be set (to any non-NULL value) or else any unsolicited en‐
46 coding done by the server is ignored.
47
48 Servers might respond with Content-Encoding even without getting a Ac‐
49 cept-Encoding: in the request. Servers might respond with a different
50 Content-Encoding than what was asked for in the request.
51
52 The Content-Length: servers send for a compressed response is supposed
53 to indicate the length of the compressed content so when auto decoding
54 is enabled it may not match the sum of bytes reported by the write
55 callbacks (although, sending the length of the non-compressed content
56 is a common server mistake).
57
58 The application does not have to keep the string around after setting
59 this option.
60
62 NULL
63
65 HTTP
66
68 CURL *curl = curl_easy_init();
69 if(curl) {
70 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
71
72 /* enable all supported built-in compressions */
73 curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
74
75 /* Perform the request */
76 curl_easy_perform(curl);
77 }
78
80 This option was called CURLOPT_ENCODING before 7.21.6
81
82 The specific libcurl you are using must have been built with zlib to be
83 able to decompress gzip and deflate responses, with the brotli library
84 to decompress brotli responses and with the zstd library to decompress
85 zstd responses.
86
88 Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if
89 not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space.
90
92 CURLOPT_TRANSFER_ENCODING(3), CURLOPT_HTTPHEADER(3), CURLOPT_HTTP_CON‐
93 TENT_DECODING(3),
94
95
96
97ibcurl 8.2.1 April 26, 2023 CURLOPT_ACCEPT_ENCODING(3)