GNURLOPT_ACCEPT_ENCODING(3)
π NAME π
okay bestie, welcome to the GNURLOPT_ACCEPT_ENCODING(3) page β it's a curl_easy_setopt options moment, and the main character is CURLOPT_ACCEPT_ENCODING, which enables automatic decompression of HTTP downloads. periodt. π
β¨
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc);
π¦ DESCRIPTION π¦
So you slide in a char * argument that says which encoding you'd like. That's the vibe. π«Ά
This sets the contents of the Accept-Encoding: header sent in an HTTP request, and it enables decoding of a response when a Content-Encoding: header is received. iconic behavior, honestly. π
libcurl potentially supports several different compressed encodings depending on what support that has been built-in. ngl, it's giving "depends on your build" energy. π¦
To aid applications not having to bother about what specific algorithms this particular libcurl build supports, libcurl allows a zero-length string to be set ("") to ask for an Accept-Encoding: header to be used that contains all built-in supported encodings. lowkey the lazy-girl option and we respect it. π
Alternatively, you can specify exactly the encoding or list of encodings you want in the response. Four encodings are supported: identity, meaning non-compressed; deflate, which requests the server to compress its response using the zlib algorithm; gzip, which requests the gzip algorithm; (since curl 7.57.0) br, which is brotli; and (since curl 7.72.0) zstd, which is zstd. Provide them in the string as a comma-separated list of accepted encodings, like:
"br, gzip, deflate".
Set CURLOPT_ACCEPT_ENCODING(3) to NULL to explicitly disable it, which makes libcurl not send an Accept-Encoding: header and not decompress received contents automatically. no cap, that's the off switch. π
You can also opt to just include the Accept-Encoding: header in your request with CURLOPT_HTTPHEADER(3) but then there will be no automatic decompressing when receiving data. so likeβ¦ you can do it, but you're on your own for the decode part. π
This is a request, not an order; the server may or may not do it. This option must be set (to any non-NULL value) or else any unsolicited encoding done by the server is ignored. fr fr, set the option or the server's little surprise encoding gets ignored. π
Servers might respond with Content-Encoding even without getting a Accept-Encoding: in the request. Servers might respond with a different Content-Encoding than what was asked for in the request. servers are gonna server, bestie. π
The Content-Length: servers send for a compressed response is supposed to indicate the length of the compressed content so when auto decoding is enabled it may not match the sum of bytes reported by the write callbacks (although, sending the length of the non-compressed content is a common server mistake). highkey important if you're counting bytes. π§
The application does not have to keep the string around after setting this option. so you can let it go after the set β it's not a situationship. π
π DEFAULT π
NULL
π PROTOCOLS π
HTTP
π EXAMPLE π
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* enable all supported built-in compressions */
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
/* Perform the request */
curl_easy_perform(curl);
}
π₯ AVAILABILITY π₯
This option was called CURLOPT_ENCODING before 7.21.6. throwback era. β
The specific libcurl you're using must have been built with zlib to be able to decompress gzip and deflate responses, with the brotli library to decompress brotli responses and with the zstd library to decompress zstd responses. so yeah, your build needs the right support β no cap. π§
π RETURN VALUE π
Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space. π memory said "not today" and that's a whole mood.
π SEE ALSO π
mwah π β this page is from libcurl 7.37.0, dated 17 Jun 2014, and the manual is GNURLOPT_ACCEPT_ENCODING(3). byeee π«ΆπΈ
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms