CURLOPT_ACCEPT_ENCODING.3 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, 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 "August 27, 2018" "libcurl 7.61.1" "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. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ACCEPT_ENCODING, char *enc);
  29. .SH DESCRIPTION
  30. Pass a char * argument specifying what encoding you'd like.
  31. Sets the contents of the Accept-Encoding: header sent in an HTTP request, and
  32. enables decoding of a response when a Content-Encoding: header is received.
  33. libcurl potentially supports several different compressed encodings depending
  34. on what support that has been built-in.
  35. To aid applications not having to bother about what specific algorithms this
  36. particular libcurl build supports, libcurl allows a zero-length string to be
  37. set ("") to ask for an Accept-Encoding: header to be used that contains all
  38. built-in supported encodings.
  39. Alternatively, you can specify exactly the encoding or list of encodings you
  40. want in the response. Four encodings are supported: \fIidentity\fP, meaning
  41. non-compressed, \fIdeflate\fP which requests the server to compress its
  42. response using the zlib algorithm, \fIgzip\fP which requests the gzip
  43. algorithm and (since curl 7.57.0) \fIbr\fP which is brotli. Provide them in
  44. the string as a comma-separated list of accepted encodings, like:
  45. "br, gzip, deflate".
  46. Set \fICURLOPT_ACCEPT_ENCODING(3)\fP to NULL to explicitly disable it, which
  47. makes libcurl not send an Accept-Encoding: header and not decompress received
  48. contents automatically.
  49. You can also opt to just include the Accept-Encoding: header in your request
  50. with \fICURLOPT_HTTPHEADER(3)\fP but then there will be no automatic
  51. decompressing when receiving data.
  52. This is a request, not an order; the server may or may not do it. This option
  53. must be set (to any non-NULL value) or else any unsolicited encoding done by
  54. the server is ignored.
  55. Servers might respond with Content-Encoding even without getting a
  56. Accept-Encoding: in the request. Servers might respond with a different
  57. Content-Encoding than what was asked for in the request.
  58. The Content-Length: servers send for a compressed response is supposed to
  59. indicate the length of the compressed content so when auto decoding is enabled
  60. it may not match the sum of bytes reported by the write callbacks (although,
  61. sending the length of the non-compressed content is a common server mistake).
  62. The application does not have to keep the string around after setting this
  63. option.
  64. .SH DEFAULT
  65. NULL
  66. .SH PROTOCOLS
  67. HTTP
  68. .SH EXAMPLE
  69. .nf
  70. CURL *curl = curl_easy_init();
  71. if(curl) {
  72. curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  73. /* enable all supported built-in compressions */
  74. curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
  75. /* Perform the request */
  76. curl_easy_perform(curl);
  77. }
  78. .fi
  79. .SH AVAILABILITY
  80. This option was called CURLOPT_ENCODING before 7.21.6
  81. The specific libcurl you're using must have been built with zlib to be able to
  82. decompress gzip and deflate responses and with the brotli library to
  83. decompress brotli responses.
  84. .SH RETURN VALUE
  85. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  86. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  87. .SH "SEE ALSO"
  88. .BR CURLOPT_TRANSFER_ENCODING "(3), " CURLOPT_HTTPHEADER "(3), "
  89. .BR CURLOPT_HTTP_CONTENT_DECODING "(3), "