1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_ACCEPT_ENCODING 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_HTTPHEADER (3) 9 - CURLOPT_HTTP_CONTENT_DECODING (3) 10 - CURLOPT_TRANSFER_ENCODING (3) 11Protocol: 12 - HTTP 13--- 14 15# NAME 16 17CURLOPT_ACCEPT_ENCODING - automatic decompression of HTTP downloads 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc); 25~~~ 26 27# DESCRIPTION 28 29Pass a char pointer argument specifying what encoding you would like. 30 31Sets the contents of the Accept-Encoding: header sent in an HTTP request, and 32enables decoding of a response when a Content-Encoding: header is received. 33 34libcurl potentially supports several different compressed encodings depending 35on what support that has been built-in. 36 37To aid applications not having to bother about what specific algorithms this 38particular libcurl build supports, libcurl allows a zero-length string to be 39set ("") to ask for an Accept-Encoding: header to be used that contains all 40built-in supported encodings. 41 42Alternatively, you can specify exactly the encoding or list of encodings you 43want in the response. The following encodings are supported: *identity*, 44meaning non-compressed, *deflate* which requests the server to compress 45its response using the zlib algorithm, *gzip* which requests the gzip 46algorithm, (since curl 7.57.0) *br* which is brotli and (since curl 477.72.0) *zstd* which is zstd. Provide them in the string as a 48comma-separated list of accepted encodings, like: **"br, gzip, deflate"**. 49 50Set CURLOPT_ACCEPT_ENCODING(3) to NULL to explicitly disable it, which 51makes libcurl not send an Accept-Encoding: header and not decompress received 52contents automatically. 53 54You can also opt to just include the Accept-Encoding: header in your request 55with CURLOPT_HTTPHEADER(3) but then there is no automatic decompressing 56when receiving data. 57 58This is a request, not an order; the server may or may not do it. This option 59must be set (to any non-NULL value) or else any unsolicited encoding done by 60the server is ignored. 61 62Servers might respond with Content-Encoding even without getting a 63Accept-Encoding: in the request. Servers might respond with a different 64Content-Encoding than what was asked for in the request. 65 66The Content-Length: servers send for a compressed response is supposed to 67indicate the length of the compressed content so when auto decoding is enabled 68it may not match the sum of bytes reported by the write callbacks (although, 69sending the length of the non-compressed content is a common server mistake). 70 71The application does not have to keep the string around after setting this 72option. 73 74# DEFAULT 75 76NULL 77 78# EXAMPLE 79 80~~~c 81int main(void) 82{ 83 CURL *curl = curl_easy_init(); 84 if(curl) { 85 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 86 87 /* enable all supported built-in compressions */ 88 curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); 89 90 /* Perform the request */ 91 curl_easy_perform(curl); 92 } 93} 94~~~ 95 96# AVAILABILITY 97 98This option was called CURLOPT_ENCODING before 7.21.6 99 100The specific libcurl you are using must have been built with zlib to be able to 101decompress gzip and deflate responses, with the brotli library to 102decompress brotli responses and with the zstd library to decompress zstd 103responses. 104 105# RETURN VALUE 106 107Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or 108CURLE_OUT_OF_MEMORY if there was insufficient heap space. 109