| 1 |
.\" ************************************************************************** |
| 2 |
.\" * _ _ ____ _ |
| 3 |
.\" * Project ___| | | | _ \| | |
| 4 |
.\" * / __| | | | |_) | | |
| 5 |
.\" * | (__| |_| | _ <| |___ |
| 6 |
.\" * \___|\___/|_| \_\_____| |
| 7 |
.\" * |
| 8 |
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <[email protected]>, et al. |
| 9 |
.\" * |
| 10 |
.\" * This software is licensed as described in the file COPYING, which |
| 11 |
.\" * you should have received as part of this distribution. The terms |
| 12 |
.\" * are also available at https://curl.haxx.se/docs/copyright.html. |
| 13 |
.\" * |
| 14 |
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 |
.\" * copies of the Software, and permit persons to whom the Software is |
| 16 |
.\" * furnished to do so, under the terms of the COPYING file. |
| 17 |
.\" * |
| 18 |
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 |
.\" * KIND, either express or implied. |
| 20 |
.\" * |
| 21 |
.\" ************************************************************************** |
| 22 |
.\" |
| 23 |
.TH CURLOPT_ACCEPT_ENCODING 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options" |
| 24 |
.SH NAME |
| 25 |
CURLOPT_ACCEPT_ENCODING \- enables automatic decompression of HTTP downloads |
| 26 |
.SH SYNOPSIS |
| 27 |
#include <curl/curl.h> |
| 28 |
|
| 29 |
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc); |
| 30 |
.SH DESCRIPTION |
| 31 |
Pass a char * argument specifying what encoding you'd like. |
| 32 |
|
| 33 |
Sets the contents of the Accept-Encoding: header sent in an HTTP request, and |
| 34 |
enables decoding of a response when a Content-Encoding: header is received. |
| 35 |
|
| 36 |
libcurl potentially supports several different compressed encodings depending |
| 37 |
on what support that has been built-in. |
| 38 |
|
| 39 |
To aid applications not having to bother about what specific algorithms this |
| 40 |
particular libcurl build supports, libcurl allows a zero-length string to be |
| 41 |
set ("") to ask for an Accept-Encoding: header to be used that contains all |
| 42 |
built-in supported encodings. |
| 43 |
|
| 44 |
Alternatively, you can specify exactly the encoding or list of encodings you |
| 45 |
want in the response. Four encodings are supported: \fIidentity\fP, meaning |
| 46 |
non-compressed, \fIdeflate\fP which requests the server to compress its |
| 47 |
response using the zlib algorithm, \fIgzip\fP which requests the gzip |
| 48 |
algorithm and (since curl 7.57.0) \fIbr\fP which is brotli. Provide them in |
| 49 |
the string as a comma-separated list of accepted encodings, like: |
| 50 |
|
| 51 |
"br, gzip, deflate". |
| 52 |
|
| 53 |
Set \fICURLOPT_ACCEPT_ENCODING(3)\fP to NULL to explicitly disable it, which |
| 54 |
makes libcurl not send an Accept-Encoding: header and not decompress received |
| 55 |
contents automatically. |
| 56 |
|
| 57 |
You can also opt to just include the Accept-Encoding: header in your request |
| 58 |
with \fICURLOPT_HTTPHEADER(3)\fP but then there will be no automatic |
| 59 |
decompressing when receiving data. |
| 60 |
|
| 61 |
This is a request, not an order; the server may or may not do it. This option |
| 62 |
must be set (to any non-NULL value) or else any unsolicited encoding done by |
| 63 |
the server is ignored. |
| 64 |
|
| 65 |
Servers might respond with Content-Encoding even without getting a |
| 66 |
Accept-Encoding: in the request. Servers might respond with a different |
| 67 |
Content-Encoding than what was asked for in the request. |
| 68 |
|
| 69 |
The Content-Length: servers send for a compressed response is supposed to |
| 70 |
indicate the length of the compressed content so when auto decoding is enabled |
| 71 |
it may not match the sum of bytes reported by the write callbacks (although, |
| 72 |
sending the length of the non-compressed content is a common server mistake). |
| 73 |
|
| 74 |
The application does not have to keep the string around after setting this |
| 75 |
option. |
| 76 |
.SH DEFAULT |
| 77 |
NULL |
| 78 |
.SH PROTOCOLS |
| 79 |
HTTP |
| 80 |
.SH EXAMPLE |
| 81 |
.nf |
| 82 |
CURL *curl = curl_easy_init(); |
| 83 |
if(curl) { |
| 84 |
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); |
| 85 |
|
| 86 |
/* enable all supported built-in compressions */ |
| 87 |
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); |
| 88 |
|
| 89 |
/* Perform the request */ |
| 90 |
curl_easy_perform(curl); |
| 91 |
} |
| 92 |
.fi |
| 93 |
.SH AVAILABILITY |
| 94 |
This option was called CURLOPT_ENCODING before 7.21.6 |
| 95 |
|
| 96 |
The specific libcurl you're using must have been built with zlib to be able to |
| 97 |
decompress gzip and deflate responses and with the brotli library to |
| 98 |
decompress brotli responses. |
| 99 |
.SH RETURN VALUE |
| 100 |
Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or |
| 101 |
CURLE_OUT_OF_MEMORY if there was insufficient heap space. |
| 102 |
.SH "SEE ALSO" |
| 103 |
.BR CURLOPT_TRANSFER_ENCODING "(3), " CURLOPT_HTTPHEADER "(3), " |
| 104 |
.BR CURLOPT_HTTP_CONTENT_DECODING "(3), " |