Support Deflate decoding (#1250)
This commit is contained in:
@@ -536,6 +536,29 @@ impl ClientBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable auto deflate decompression by checking the `Content-Encoding` response header.
|
||||
///
|
||||
/// If auto deflate decompression is turned on:
|
||||
///
|
||||
/// - When sending a request and if the request's headers do not already contain
|
||||
/// an `Accept-Encoding` **and** `Range` values, the `Accept-Encoding` header is set to `deflate`.
|
||||
/// The request body is **not** automatically compressed.
|
||||
/// - When receiving a response, if it's headers contain a `Content-Encoding` value that
|
||||
/// equals to `deflate`, both values `Content-Encoding` and `Content-Length` are removed from the
|
||||
/// headers' set. The response body is automatically decompressed.
|
||||
///
|
||||
/// If the `deflate` feature is turned on, the default option is enabled.
|
||||
///
|
||||
/// # Optional
|
||||
///
|
||||
/// This requires the optional `deflate` feature to be enabled
|
||||
#[cfg(feature = "deflate")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "deflate")))]
|
||||
pub fn deflate(mut self, enable: bool) -> ClientBuilder {
|
||||
self.config.accepts.deflate = enable;
|
||||
self
|
||||
}
|
||||
|
||||
/// Disable auto response body gzip decompression.
|
||||
///
|
||||
/// This method exists even if the optional `gzip` feature is not enabled.
|
||||
@@ -570,6 +593,23 @@ impl ClientBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Disable auto response body deflate decompression.
|
||||
///
|
||||
/// This method exists even if the optional `deflate` feature is not enabled.
|
||||
/// This can be used to ensure a `Client` doesn't use deflate decompression
|
||||
/// even if another dependency were to enable the optional `deflate` feature.
|
||||
pub fn no_deflate(self) -> ClientBuilder {
|
||||
#[cfg(feature = "deflate")]
|
||||
{
|
||||
self.deflate(false)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "deflate"))]
|
||||
{
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect options
|
||||
|
||||
/// Set a `RedirectPolicy` for this client.
|
||||
|
||||
Reference in New Issue
Block a user