1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-23 16:21:06 +01:00

compile with default-features off

This commit is contained in:
Nikolay Kim 2019-12-15 13:28:54 +06:00
parent e8e0f98f96
commit cb705317b8
9 changed files with 79 additions and 20 deletions

View File

@ -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" }

View File

@ -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"

View File

@ -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"] }

View File

@ -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<ClientResponse<Decoder<Payload<PayloadStream>>>, 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<ClientResponse, SendRequestError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
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<SendRequestError> for SendClientRequest {
fn from(e: SendRequestError) -> Self {
SendClientRequest::Err(Some(e))

View File

@ -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::{

View File

@ -1,5 +1,8 @@
//! Middlewares
#[cfg(feature = "compress")]
mod compress;
#[cfg(feature = "compress")]
pub use self::compress::{BodyEncoding, Compress};
mod condition;

View File

@ -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<U> {
#[cfg(feature = "compress")]
stream: Option<Decompress<Payload>>,
#[cfg(not(feature = "compress"))]
stream: Option<Payload>,
limit: usize,
length: Option<usize>,
encoding: &'static Encoding,
@ -273,7 +277,11 @@ impl<U> UrlEncoded<U> {
}
};
#[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),

View File

@ -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<U> {
limit: usize,
length: Option<usize>,
#[cfg(feature = "compress")]
stream: Option<Decompress<Payload>>,
#[cfg(not(feature = "compress"))]
stream: Option<Payload>,
err: Option<JsonPayloadError>,
fut: Option<LocalBoxFuture<'static, Result<U, JsonPayloadError>>>,
}
@ -332,7 +336,11 @@ where
.get(&CONTENT_LENGTH)
.and_then(|l| l.to_str().ok())
.and_then(|s| s.parse::<usize>().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,

View File

@ -301,7 +301,10 @@ impl Default for PayloadConfig {
pub struct HttpMessageBody {
limit: usize,
length: Option<usize>,
#[cfg(feature = "compress")]
stream: Option<dev::Decompress<dev::Payload>>,
#[cfg(not(feature = "compress"))]
stream: Option<dev::Payload>,
err: Option<PayloadError>,
fut: Option<LocalBoxFuture<'static, Result<Bytes, PayloadError>>>,
}
@ -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,