From cb705317b8f70ecb4681806836c70d4cb3a0aedf Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 15 Dec 2019 13:28:54 +0600 Subject: [PATCH] compile with default-features off --- Cargo.toml | 22 +++++++++++----------- actix-http/Cargo.toml | 2 +- awc/Cargo.toml | 4 ++-- awc/src/sender.rs | 41 ++++++++++++++++++++++++++++++++++++----- src/lib.rs | 1 + src/middleware/mod.rs | 3 +++ src/types/form.rs | 8 ++++++++ src/types/json.rs | 8 ++++++++ src/types/payload.rs | 10 +++++++++- 9 files changed, 79 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6f13b376..1659515e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,14 +106,14 @@ lto = true opt-level = 3 codegen-units = 1 -# [patch.crates-io] -# actix-web = { path = "." } -# actix-http = { path = "actix-http" } -# actix-http-test = { path = "test-server" } -# actix-web-codegen = { path = "actix-web-codegen" } -# actix-cors = { path = "actix-cors" } -# actix-identity = { path = "actix-identity" } -# actix-session = { path = "actix-session" } -# actix-files = { path = "actix-files" } -# actix-multipart = { path = "actix-multipart" } -# awc = { path = "awc" } +[patch.crates-io] +actix-web = { path = "." } +actix-http = { path = "actix-http" } +actix-http-test = { path = "test-server" } +actix-web-codegen = { path = "actix-web-codegen" } +actix-cors = { path = "actix-cors" } +actix-identity = { path = "actix-identity" } +actix-session = { path = "actix-session" } +actix-files = { path = "actix-files" } +actix-multipart = { path = "actix-multipart" } +awc = { path = "awc" } diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index dfa9874a..6669c793 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -42,7 +42,7 @@ secure-cookies = ["ring"] [dependencies] actix-service = "1.0.0" actix-codec = "0.2.0" -actix-connect = "1.0.0" +actix-connect = "1.0.1" actix-utils = "1.0.3" actix-rt = "1.0.0" actix-threadpool = "0.3.1" diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 28931916..26d1e85d 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -22,7 +22,7 @@ path = "src/lib.rs" features = ["openssl", "rustls", "compress"] [features] -default = ["compress"] +default = [] #"compress"] # openssl openssl = ["open-ssl", "actix-http/openssl"] @@ -54,7 +54,7 @@ open-ssl = { version="0.10", package="openssl", optional = true } rust-tls = { version = "0.16.0", package="rustls", optional = true, features = ["dangerous_configuration"] } [dev-dependencies] -actix-connect = { version = "1.0.0", features=["openssl"] } +actix-connect = { version = "1.0.1", features=["openssl"] } actix-web = { version = "2.0.0-alpha.5", features=["openssl"] } actix-http = { version = "1.0.0", features=["openssl"] } actix-http-test = { version = "1.0.0", features=["openssl"] } diff --git a/awc/src/sender.rs b/awc/src/sender.rs index 7381e77b..ec18f12e 100644 --- a/awc/src/sender.rs +++ b/awc/src/sender.rs @@ -7,15 +7,21 @@ use std::time::Duration; use actix_rt::time::{delay_for, Delay}; use bytes::Bytes; use derive_more::From; -use futures_core::{ready, Future, Stream}; +use futures_core::{Future, Stream}; use serde::Serialize; use serde_json; use actix_http::body::{Body, BodyStream}; -use actix_http::encoding::Decoder; -use actix_http::http::header::{self, ContentEncoding, IntoHeaderValue}; +use actix_http::http::header::{self, IntoHeaderValue}; use actix_http::http::{Error as HttpError, HeaderMap, HeaderName}; -use actix_http::{Error, Payload, PayloadStream, RequestHead}; +use actix_http::{Error, RequestHead}; + +#[cfg(feature = "compress")] +use actix_http::encoding::Decoder; +#[cfg(feature = "compress")] +use actix_http::http::header::ContentEncoding; +#[cfg(feature = "compress")] +use actix_http::{Payload, PayloadStream}; use crate::error::{FreezeRequestError, InvalidUrl, SendRequestError}; use crate::response::ClientResponse; @@ -67,6 +73,7 @@ impl SendClientRequest { } } +#[cfg(feature = "compress")] impl Future for SendClientRequest { type Output = Result>>, SendRequestError>; @@ -83,7 +90,7 @@ impl Future for SendClientRequest { } } - let res = ready!(Pin::new(send).poll(cx)).map(|res| { + let res = futures_core::ready!(Pin::new(send).poll(cx)).map(|res| { res.map_body(|head, payload| { if *response_decompress { Payload::Stream(Decoder::from_headers( @@ -109,6 +116,30 @@ impl Future for SendClientRequest { } } +#[cfg(not(feature = "compress"))] +impl Future for SendClientRequest { + type Output = Result; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let this = self.get_mut(); + match this { + SendClientRequest::Fut(send, delay, _) => { + if delay.is_some() { + match Pin::new(delay.as_mut().unwrap()).poll(cx) { + Poll::Pending => (), + _ => return Poll::Ready(Err(SendRequestError::Timeout)), + } + } + Pin::new(send).poll(cx) + } + SendClientRequest::Err(ref mut e) => match e.take() { + Some(e) => Poll::Ready(Err(e)), + None => panic!("Attempting to call completed future"), + }, + } + } +} + impl From for SendClientRequest { fn from(e: SendRequestError) -> Self { SendClientRequest::Err(Some(e)) diff --git a/src/lib.rs b/src/lib.rs index 7a1dbec0..acb0da10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -141,6 +141,7 @@ pub mod dev { pub use crate::types::readlines::Readlines; pub use actix_http::body::{Body, BodySize, MessageBody, ResponseBody, SizedStream}; + #[cfg(feature = "compress")] pub use actix_http::encoding::Decoder as Decompress; pub use actix_http::ResponseBuilder as HttpResponseBuilder; pub use actix_http::{ diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 84e0758b..be23230c 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -1,5 +1,8 @@ //! Middlewares + +#[cfg(feature = "compress")] mod compress; +#[cfg(feature = "compress")] pub use self::compress::{BodyEncoding, Compress}; mod condition; diff --git a/src/types/form.rs b/src/types/form.rs index 977f88d0..756d5fcc 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -14,6 +14,7 @@ use futures::StreamExt; use serde::de::DeserializeOwned; use serde::Serialize; +#[cfg(feature = "compress")] use crate::dev::Decompress; use crate::error::UrlencodedError; use crate::extract::FromRequest; @@ -240,7 +241,10 @@ impl Default for FormConfig { /// * content-length is greater than 32k /// pub struct UrlEncoded { + #[cfg(feature = "compress")] stream: Option>, + #[cfg(not(feature = "compress"))] + stream: Option, limit: usize, length: Option, encoding: &'static Encoding, @@ -273,7 +277,11 @@ impl UrlEncoded { } }; + #[cfg(feature = "compress")] let payload = Decompress::from_headers(payload.take(), req.headers()); + #[cfg(not(feature = "compress"))] + let payload = payload.take(); + UrlEncoded { encoding, stream: Some(payload), diff --git a/src/types/json.rs b/src/types/json.rs index 8112d04f..03c4a2db 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -16,6 +16,7 @@ use serde_json; use actix_http::http::{header::CONTENT_LENGTH, StatusCode}; use actix_http::{HttpMessage, Payload, Response}; +#[cfg(feature = "compress")] use crate::dev::Decompress; use crate::error::{Error, JsonPayloadError}; use crate::extract::FromRequest; @@ -293,7 +294,10 @@ impl Default for JsonConfig { pub struct JsonBody { limit: usize, length: Option, + #[cfg(feature = "compress")] stream: Option>, + #[cfg(not(feature = "compress"))] + stream: Option, err: Option, fut: Option>>, } @@ -332,7 +336,11 @@ where .get(&CONTENT_LENGTH) .and_then(|l| l.to_str().ok()) .and_then(|s| s.parse::().ok()); + + #[cfg(feature = "compress")] let payload = Decompress::from_headers(payload.take(), req.headers()); + #[cfg(not(feature = "compress"))] + let payload = payload.take(); JsonBody { limit: 262_144, diff --git a/src/types/payload.rs b/src/types/payload.rs index 8e52a3b6..7cb714a8 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -301,7 +301,10 @@ impl Default for PayloadConfig { pub struct HttpMessageBody { limit: usize, length: Option, + #[cfg(feature = "compress")] stream: Option>, + #[cfg(not(feature = "compress"))] + stream: Option, err: Option, fut: Option>>, } @@ -322,8 +325,13 @@ impl HttpMessageBody { } } + #[cfg(feature = "compress")] + let stream = Some(dev::Decompress::from_headers(payload.take(), req.headers())); + #[cfg(not(feature = "compress"))] + let stream = Some(payload.take()); + HttpMessageBody { - stream: Some(dev::Decompress::from_headers(payload.take(), req.headers())), + stream, limit: 262_144, length: len, fut: None,