use ZlibDecoder for deflate responses (#1257)
This commit is contained in:
@@ -49,7 +49,7 @@ gzip = ["async-compression", "async-compression/gzip", "tokio-util"]
|
|||||||
|
|
||||||
brotli = ["async-compression", "async-compression/brotli", "tokio-util"]
|
brotli = ["async-compression", "async-compression/brotli", "tokio-util"]
|
||||||
|
|
||||||
deflate = ["async-compression", "async-compression/deflate", "tokio-util"]
|
deflate = ["async-compression", "async-compression/zlib", "tokio-util"]
|
||||||
|
|
||||||
json = ["serde_json"]
|
json = ["serde_json"]
|
||||||
|
|
||||||
@@ -197,6 +197,7 @@ path = "examples/form.rs"
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "simple"
|
name = "simple"
|
||||||
path = "examples/simple.rs"
|
path = "examples/simple.rs"
|
||||||
|
required-features = ["deflate"]
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "blocking"
|
name = "blocking"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use async_compression::tokio::bufread::GzipDecoder;
|
|||||||
use async_compression::tokio::bufread::BrotliDecoder;
|
use async_compression::tokio::bufread::BrotliDecoder;
|
||||||
|
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "deflate")]
|
||||||
use async_compression::tokio::bufread::DeflateDecoder;
|
use async_compression::tokio::bufread::ZlibDecoder;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
@@ -57,7 +57,7 @@ enum Inner {
|
|||||||
|
|
||||||
/// A `Deflate` decoder will uncompress the deflated response content before returning it.
|
/// A `Deflate` decoder will uncompress the deflated response content before returning it.
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "deflate")]
|
||||||
Deflate(FramedRead<DeflateDecoder<StreamReader<Peekable<IoStream>, Bytes>>, BytesCodec>),
|
Deflate(FramedRead<ZlibDecoder<StreamReader<Peekable<IoStream>, Bytes>>, BytesCodec>),
|
||||||
|
|
||||||
/// A decoder that doesn't have a value yet.
|
/// A decoder that doesn't have a value yet.
|
||||||
#[cfg(any(feature = "brotli", feature = "gzip", feature = "deflate"))]
|
#[cfg(any(feature = "brotli", feature = "gzip", feature = "deflate"))]
|
||||||
@@ -321,7 +321,7 @@ impl Future for Pending {
|
|||||||
)))),
|
)))),
|
||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "deflate")]
|
||||||
DecoderType::Deflate => Poll::Ready(Ok(Inner::Deflate(FramedRead::new(
|
DecoderType::Deflate => Poll::Ready(Ok(Inner::Deflate(FramedRead::new(
|
||||||
DeflateDecoder::new(StreamReader::new(_body)),
|
ZlibDecoder::new(StreamReader::new(_body)),
|
||||||
BytesCodec::new(),
|
BytesCodec::new(),
|
||||||
)))),
|
)))),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ async fn deflate_case(response_size: usize, chunk_size: usize) {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| format!("test {}", i))
|
.map(|i| format!("test {}", i))
|
||||||
.collect();
|
.collect();
|
||||||
let mut encoder = libflate::deflate::Encoder::new(Vec::new());
|
let mut encoder = libflate::zlib::Encoder::new(Vec::new()).unwrap();
|
||||||
match encoder.write(content.as_bytes()) {
|
match encoder.write(content.as_bytes()) {
|
||||||
Ok(n) => assert!(n > 0, "Failed to write to encoder."),
|
Ok(n) => assert!(n > 0, "Failed to write to encoder."),
|
||||||
_ => panic!("Failed to deflate encode string."),
|
_ => panic!("Failed to deflate encode string."),
|
||||||
|
|||||||
Reference in New Issue
Block a user