You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To allow `cpr` and therefore `libcurl` decide which compressions are accepted, or just to enable all supported compression methods, pass an empty list to `cpr::AcceptEncoding`.
289
+
**This is also the default behavior if nothing else gets configured.**
290
+
291
+
{% raw %}
292
+
```c++
293
+
// An empty list of accepted encodings in combination with a direct request without any state
294
+
cpr::Response r = cpr::Get(cpr::Url{"http://www.httpbin.org/get"},
295
+
cpr::AcceptEncoding{});
296
+
297
+
// An empty list of accepted encodings in combination with a stateful cpr::Session object
298
+
session.SetAcceptEncoding(cpr::AcceptEncoding{});
299
+
```
300
+
{% endraw %}
301
+
302
+
### Disabling the `Accept-Encoding` Header
303
+
304
+
By default `cpr` and therefore `libcurl` will always include an `Accept-Encoding` header. To disable this behavior one can simply pass the `cpr::AcceptEncodingMethods::disabled` or `"disabled"` directly as a `std::string` to `cpr::AcceptEncoding`.
305
+
306
+
> ⚠️ **WARNING**<br>
307
+
> Including `cpr::AcceptEncodingMethods::disabled` or `"disabled"` does not allow any other values/encodings to be passed to `cpr::AcceptEncoding`!<br>
308
+
> If you ignore this a `std::invalid_argument` exception wil be thrown during session establishment.
309
+
310
+
{% raw %}
311
+
```c++
312
+
cpr::Session session;
313
+
session.SetUrl("https://example.com");
314
+
session.SetAcceptEncoding({AcceptEncodingMethods::disabled}); // Disable setting the `Accept-Encoding` header
315
+
Response response = session.Get();
316
+
```
317
+
{% endraw %}
318
+
319
+
{% raw %}
320
+
```c++
321
+
cpr::Session session;
322
+
session.SetUrl("https://example.com");
323
+
session.SetAcceptEncoding({"disabled"}); // Disable setting the `Accept-Encoding` header
Response response = session.Get(); // An exception of type `std::invalid_argument` will be thrown here since multiple values are passed to `AcceptEncoding` where one of them is `disabled`
334
+
```
335
+
{% endraw %}
336
+
286
337
For more information, please refer to [HTTP compression - Wikipedia](https://en.wikipedia.org/wiki/HTTP_compression) and [CURLOPT_ACCEPT_ENCODING](https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html).
0 commit comments