CURLOPT_ACCEPT_ENCODING.3 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. .\" generated by cd2nroff 0.1 from CURLOPT_ACCEPT_ENCODING.md
  2. .TH CURLOPT_ACCEPT_ENCODING 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_ACCEPT_ENCODING \- automatic decompression of HTTP downloads
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a char pointer argument specifying what encoding you would like.
  12. Sets the contents of the Accept\-Encoding: header sent in an HTTP request, and
  13. enables decoding of a response when a Content\-Encoding: header is received.
  14. libcurl potentially supports several different compressed encodings depending
  15. on what support that has been built\-in.
  16. To aid applications not having to bother about what specific algorithms this
  17. particular libcurl build supports, libcurl allows a zero\-length string to be
  18. set ("") to ask for an Accept\-Encoding: header to be used that contains all
  19. built\-in supported encodings.
  20. Alternatively, you can specify exactly the encoding or list of encodings you
  21. want in the response. The following encodings are supported: \fIidentity\fP,
  22. meaning non\-compressed, \fIdeflate\fP which requests the server to compress
  23. its response using the zlib algorithm, \fIgzip\fP which requests the gzip
  24. algorithm, (since curl 7.57.0) \fIbr\fP which is brotli and (since curl
  25. 7.72.0) \fIzstd\fP which is zstd. Provide them in the string as a
  26. comma\-separated list of accepted encodings, like: \fB"br, gzip, deflate"\fP.
  27. Set \fICURLOPT_ACCEPT_ENCODING(3)\fP to NULL to explicitly disable it, which
  28. makes libcurl not send an Accept\-Encoding: header and not decompress received
  29. contents automatically.
  30. You can also opt to just include the Accept\-Encoding: header in your request
  31. with \fICURLOPT_HTTPHEADER(3)\fP but then there is no automatic decompressing
  32. when receiving data.
  33. This is a request, not an order; the server may or may not do it. This option
  34. must be set (to any non\-NULL value) or else any unsolicited encoding done by
  35. the server is ignored.
  36. Servers might respond with Content\-Encoding even without getting a
  37. Accept\-Encoding: in the request. Servers might respond with a different
  38. Content\-Encoding than what was asked for in the request.
  39. The Content\-Length: servers send for a compressed response is supposed to
  40. indicate the length of the compressed content so when auto decoding is enabled
  41. it may not match the sum of bytes reported by the write callbacks (although,
  42. sending the length of the non\-compressed content is a common server mistake).
  43. The application does not have to keep the string around after setting this
  44. option.
  45. .SH HISTORY
  46. This option was called CURLOPT_ENCODING before 7.21.6
  47. .SH NOTES
  48. The specific libcurl you are using must have been built with zlib to be able to
  49. decompress gzip and deflate responses, with the brotli library to
  50. decompress brotli responses and with the zstd library to decompress zstd
  51. responses.
  52. .SH DEFAULT
  53. NULL
  54. .SH PROTOCOLS
  55. This functionality affects http only
  56. .SH EXAMPLE
  57. .nf
  58. int main(void)
  59. {
  60. CURL *curl = curl_easy_init();
  61. if(curl) {
  62. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  63. /* enable all supported built-in compressions */
  64. curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
  65. /* Perform the request */
  66. curl_easy_perform(curl);
  67. }
  68. }
  69. .fi
  70. .SH AVAILABILITY
  71. Added in curl 7.21.6
  72. .SH RETURN VALUE
  73. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  74. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  75. .SH SEE ALSO
  76. .BR CURLOPT_HTTPHEADER (3),
  77. .BR CURLOPT_HTTP_CONTENT_DECODING (3),
  78. .BR CURLOPT_TRANSFER_ENCODING (3)