mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-02 18:59:04 +01:00
Fix compilation with --no-default-features
This commit is contained in:
parent
16906c5951
commit
537b420d35
@ -1,5 +1,10 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## 0.6.7 (2018-05-17)
|
||||||
|
|
||||||
|
* Fix compilation with --no-default-features
|
||||||
|
|
||||||
|
|
||||||
## 0.6.6 (2018-05-17)
|
## 0.6.6 (2018-05-17)
|
||||||
|
|
||||||
* Panic during middleware execution #226
|
* Panic during middleware execution #226
|
||||||
|
@ -33,6 +33,7 @@ pub(crate) enum PayloadType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PayloadType {
|
impl PayloadType {
|
||||||
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
pub fn new(headers: &HeaderMap, sender: PayloadSender) -> PayloadType {
|
pub fn new(headers: &HeaderMap, sender: PayloadSender) -> PayloadType {
|
||||||
// check content-encoding
|
// check content-encoding
|
||||||
let enc = if let Some(enc) = headers.get(CONTENT_ENCODING) {
|
let enc = if let Some(enc) = headers.get(CONTENT_ENCODING) {
|
||||||
@ -52,6 +53,11 @@ impl PayloadType {
|
|||||||
_ => PayloadType::Encoding(Box::new(EncodedPayload::new(sender, enc))),
|
_ => PayloadType::Encoding(Box::new(EncodedPayload::new(sender, enc))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "brotli", feature = "flate2")))]
|
||||||
|
pub fn new(headers: &HeaderMap, sender: PayloadSender) -> PayloadType {
|
||||||
|
PayloadType::Sender(sender)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PayloadWriter for PayloadType {
|
impl PayloadWriter for PayloadType {
|
||||||
@ -399,6 +405,7 @@ impl ContentEncoder {
|
|||||||
|
|
||||||
// Enable content encoding only if response does not contain Content-Encoding
|
// Enable content encoding only if response does not contain Content-Encoding
|
||||||
// header
|
// header
|
||||||
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
let mut encoding = if has_body {
|
let mut encoding = if has_body {
|
||||||
let encoding = match response_encoding {
|
let encoding = match response_encoding {
|
||||||
ContentEncoding::Auto => {
|
ContentEncoding::Auto => {
|
||||||
@ -425,6 +432,8 @@ impl ContentEncoder {
|
|||||||
} else {
|
} else {
|
||||||
ContentEncoding::Identity
|
ContentEncoding::Identity
|
||||||
};
|
};
|
||||||
|
#[cfg(not(any(feature = "brotli", feature = "flate2")))]
|
||||||
|
let mut encoding = ContentEncoding::Identity;
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(match_ref_pats))]
|
#[cfg_attr(feature = "cargo-clippy", allow(match_ref_pats))]
|
||||||
let mut transfer = match resp.body() {
|
let mut transfer = match resp.body() {
|
||||||
@ -435,40 +444,42 @@ impl ContentEncoder {
|
|||||||
TransferEncoding::length(0, buf)
|
TransferEncoding::length(0, buf)
|
||||||
}
|
}
|
||||||
&Body::Binary(_) => {
|
&Body::Binary(_) => {
|
||||||
if !(encoding == ContentEncoding::Identity
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
|| encoding == ContentEncoding::Auto)
|
|
||||||
{
|
{
|
||||||
let tmp = SharedBytes::default();
|
if !(encoding == ContentEncoding::Identity
|
||||||
let transfer = TransferEncoding::eof(tmp.clone());
|
|| encoding == ContentEncoding::Auto)
|
||||||
let mut enc = match encoding {
|
{
|
||||||
#[cfg(feature = "flate2")]
|
let tmp = SharedBytes::default();
|
||||||
ContentEncoding::Deflate => ContentEncoder::Deflate(
|
let transfer = TransferEncoding::eof(tmp.clone());
|
||||||
DeflateEncoder::new(transfer, Compression::fast()),
|
let mut enc = match encoding {
|
||||||
),
|
#[cfg(feature = "flate2")]
|
||||||
#[cfg(feature = "flate2")]
|
ContentEncoding::Deflate => ContentEncoder::Deflate(
|
||||||
ContentEncoding::Gzip => ContentEncoder::Gzip(GzEncoder::new(
|
DeflateEncoder::new(transfer, Compression::fast()),
|
||||||
transfer,
|
),
|
||||||
Compression::fast(),
|
#[cfg(feature = "flate2")]
|
||||||
)),
|
ContentEncoding::Gzip => ContentEncoder::Gzip(
|
||||||
#[cfg(feature = "brotli")]
|
GzEncoder::new(transfer, Compression::fast()),
|
||||||
ContentEncoding::Br => {
|
),
|
||||||
ContentEncoder::Br(BrotliEncoder::new(transfer, 3))
|
#[cfg(feature = "brotli")]
|
||||||
}
|
ContentEncoding::Br => {
|
||||||
ContentEncoding::Identity | ContentEncoding::Auto => {
|
ContentEncoder::Br(BrotliEncoder::new(transfer, 3))
|
||||||
unreachable!()
|
}
|
||||||
}
|
ContentEncoding::Identity | ContentEncoding::Auto => {
|
||||||
};
|
unreachable!()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let bin = resp.replace_body(Body::Empty).binary();
|
let bin = resp.replace_body(Body::Empty).binary();
|
||||||
|
|
||||||
// TODO return error!
|
// TODO return error!
|
||||||
let _ = enc.write(bin);
|
let _ = enc.write(bin);
|
||||||
let _ = enc.write_eof();
|
let _ = enc.write_eof();
|
||||||
let body = tmp.take();
|
let body = tmp.take();
|
||||||
len = body.len();
|
len = body.len();
|
||||||
|
|
||||||
encoding = ContentEncoding::Identity;
|
encoding = ContentEncoding::Identity;
|
||||||
resp.replace_body(Binary::from(body));
|
resp.replace_body(Binary::from(body));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_head {
|
if is_head {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user