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