mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into master
This commit is contained in:
commit
af15f55917
|
@ -1,14 +1,12 @@
|
||||||
name: Upload documentation
|
name: Upload Documentation
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [master]
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.repository == 'actix/actix-web'
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -20,14 +18,14 @@ jobs:
|
||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: check build
|
- name: Build Docs
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: doc
|
command: doc
|
||||||
args: --workspace --all-features --no-deps
|
args: --workspace --all-features --no-deps
|
||||||
|
|
||||||
- name: Tweak HTML
|
- name: Tweak HTML
|
||||||
run: echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html
|
run: echo '<meta http-equiv="refresh" content="0;url=actix_web/index.html">' > target/doc/index.html
|
||||||
|
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||||
|
|
|
@ -66,7 +66,7 @@ required-features = ["compress"]
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "test_server"
|
name = "test_server"
|
||||||
required-features = ["compress"]
|
required-features = ["compress", "cookies"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "on_connect"
|
name = "on_connect"
|
||||||
|
@ -84,7 +84,7 @@ actix-rt = "2"
|
||||||
actix-server = "2.0.0-beta.3"
|
actix-server = "2.0.0-beta.3"
|
||||||
actix-service = "2.0.0-beta.4"
|
actix-service = "2.0.0-beta.4"
|
||||||
actix-utils = "3.0.0-beta.2"
|
actix-utils = "3.0.0-beta.2"
|
||||||
actix-tls = { version = "3.0.0-beta.3", default-features = false, optional = true }
|
actix-tls = { version = "3.0.0-beta.4", default-features = false, optional = true }
|
||||||
|
|
||||||
actix-web-codegen = "0.5.0-beta.1"
|
actix-web-codegen = "0.5.0-beta.1"
|
||||||
actix-http = "3.0.0-beta.3"
|
actix-http = "3.0.0-beta.3"
|
||||||
|
|
|
@ -31,7 +31,7 @@ openssl = ["tls-openssl", "awc/openssl"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "2.0.0-beta.4"
|
actix-service = "2.0.0-beta.4"
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-tls = "3.0.0-beta.3"
|
actix-tls = "3.0.0-beta.4"
|
||||||
actix-utils = "3.0.0-beta.2"
|
actix-utils = "3.0.0-beta.2"
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
actix-server = "2.0.0-beta.3"
|
actix-server = "2.0.0-beta.3"
|
||||||
|
|
|
@ -48,7 +48,7 @@ actix-service = "2.0.0-beta.4"
|
||||||
actix-codec = "0.4.0-beta.1"
|
actix-codec = "0.4.0-beta.1"
|
||||||
actix-utils = "3.0.0-beta.2"
|
actix-utils = "3.0.0-beta.2"
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
actix-tls = "3.0.0-beta.2"
|
actix-tls = "3.0.0-beta.4"
|
||||||
|
|
||||||
ahash = "0.7"
|
ahash = "0.7"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
|
@ -61,7 +61,7 @@ derive_more = "0.99.5"
|
||||||
encoding_rs = "0.8"
|
encoding_rs = "0.8"
|
||||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||||
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
|
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
|
||||||
h2 = "0.3.0"
|
h2 = "=0.3.0"
|
||||||
http = "0.2.2"
|
http = "0.2.2"
|
||||||
httparse = "1.3"
|
httparse = "1.3"
|
||||||
itoa = "0.4"
|
itoa = "0.4"
|
||||||
|
@ -90,7 +90,7 @@ trust-dns-resolver = { version = "0.20.0", optional = true }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-server = "2.0.0-beta.3"
|
actix-server = "2.0.0-beta.3"
|
||||||
actix-http-test = { version = "3.0.0-beta.2", features = ["openssl"] }
|
actix-http-test = { version = "3.0.0-beta.2", features = ["openssl"] }
|
||||||
actix-tls = { version = "3.0.0-beta.2", features = ["openssl"] }
|
actix-tls = { version = "3.0.0-beta.4", features = ["openssl"] }
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
rcgen = "0.8"
|
rcgen = "0.8"
|
||||||
|
|
|
@ -94,10 +94,10 @@ mod openssl {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use actix_service::ServiceFactoryExt;
|
use actix_service::ServiceFactoryExt;
|
||||||
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, SslStream};
|
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream};
|
||||||
use actix_tls::accept::TlsError;
|
use actix_tls::accept::TlsError;
|
||||||
|
|
||||||
impl<S, B, X, U> H1Service<SslStream<TcpStream>, S, B, X, U>
|
impl<S, B, X, U> H1Service<TlsStream<TcpStream>, S, B, X, U>
|
||||||
where
|
where
|
||||||
S: ServiceFactory<Request, Config = ()>,
|
S: ServiceFactory<Request, Config = ()>,
|
||||||
S::Error: Into<Error>,
|
S::Error: Into<Error>,
|
||||||
|
@ -108,7 +108,7 @@ mod openssl {
|
||||||
X::Error: Into<Error>,
|
X::Error: Into<Error>,
|
||||||
X::InitError: fmt::Debug,
|
X::InitError: fmt::Debug,
|
||||||
U: ServiceFactory<
|
U: ServiceFactory<
|
||||||
(Request, Framed<SslStream<TcpStream>, Codec>),
|
(Request, Framed<TlsStream<TcpStream>, Codec>),
|
||||||
Config = (),
|
Config = (),
|
||||||
Response = (),
|
Response = (),
|
||||||
>,
|
>,
|
||||||
|
@ -131,7 +131,7 @@ mod openssl {
|
||||||
.map_err(TlsError::Tls)
|
.map_err(TlsError::Tls)
|
||||||
.map_init_err(|_| panic!()),
|
.map_init_err(|_| panic!()),
|
||||||
)
|
)
|
||||||
.and_then(|io: SslStream<TcpStream>| {
|
.and_then(|io: TlsStream<TcpStream>| {
|
||||||
let peer_addr = io.get_ref().peer_addr().ok();
|
let peer_addr = io.get_ref().peer_addr().ok();
|
||||||
ready(Ok((io, peer_addr)))
|
ready(Ok((io, peer_addr)))
|
||||||
})
|
})
|
||||||
|
|
|
@ -93,12 +93,12 @@ where
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
mod openssl {
|
mod openssl {
|
||||||
use actix_service::{fn_factory, fn_service, ServiceFactoryExt};
|
use actix_service::{fn_factory, fn_service, ServiceFactoryExt};
|
||||||
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, SslStream};
|
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream};
|
||||||
use actix_tls::accept::TlsError;
|
use actix_tls::accept::TlsError;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl<S, B> H2Service<SslStream<TcpStream>, S, B>
|
impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
|
||||||
where
|
where
|
||||||
S: ServiceFactory<Request, Config = ()>,
|
S: ServiceFactory<Request, Config = ()>,
|
||||||
S::Error: Into<Error> + 'static,
|
S::Error: Into<Error> + 'static,
|
||||||
|
@ -123,7 +123,7 @@ mod openssl {
|
||||||
.map_init_err(|_| panic!()),
|
.map_init_err(|_| panic!()),
|
||||||
)
|
)
|
||||||
.and_then(fn_factory(|| {
|
.and_then(fn_factory(|| {
|
||||||
ok::<_, S::InitError>(fn_service(|io: SslStream<TcpStream>| {
|
ok::<_, S::InitError>(fn_service(|io: TlsStream<TcpStream>| {
|
||||||
let peer_addr = io.get_ref().peer_addr().ok();
|
let peer_addr = io.get_ref().peer_addr().ok();
|
||||||
ok((io, peer_addr))
|
ok((io, peer_addr))
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -185,10 +185,10 @@ where
|
||||||
mod openssl {
|
mod openssl {
|
||||||
use super::*;
|
use super::*;
|
||||||
use actix_service::ServiceFactoryExt;
|
use actix_service::ServiceFactoryExt;
|
||||||
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, SslStream};
|
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream};
|
||||||
use actix_tls::accept::TlsError;
|
use actix_tls::accept::TlsError;
|
||||||
|
|
||||||
impl<S, B, X, U> HttpService<SslStream<TcpStream>, S, B, X, U>
|
impl<S, B, X, U> HttpService<TlsStream<TcpStream>, S, B, X, U>
|
||||||
where
|
where
|
||||||
S: ServiceFactory<Request, Config = ()>,
|
S: ServiceFactory<Request, Config = ()>,
|
||||||
S::Error: Into<Error> + 'static,
|
S::Error: Into<Error> + 'static,
|
||||||
|
@ -201,13 +201,13 @@ mod openssl {
|
||||||
X::InitError: fmt::Debug,
|
X::InitError: fmt::Debug,
|
||||||
<X::Service as Service<Request>>::Future: 'static,
|
<X::Service as Service<Request>>::Future: 'static,
|
||||||
U: ServiceFactory<
|
U: ServiceFactory<
|
||||||
(Request, Framed<SslStream<TcpStream>, h1::Codec>),
|
(Request, Framed<TlsStream<TcpStream>, h1::Codec>),
|
||||||
Config = (),
|
Config = (),
|
||||||
Response = (),
|
Response = (),
|
||||||
>,
|
>,
|
||||||
U::Error: fmt::Display + Into<Error>,
|
U::Error: fmt::Display + Into<Error>,
|
||||||
U::InitError: fmt::Debug,
|
U::InitError: fmt::Debug,
|
||||||
<U::Service as Service<(Request, Framed<SslStream<TcpStream>, h1::Codec>)>>::Future: 'static,
|
<U::Service as Service<(Request, Framed<TlsStream<TcpStream>, h1::Codec>)>>::Future: 'static,
|
||||||
{
|
{
|
||||||
/// Create openssl based service
|
/// Create openssl based service
|
||||||
pub fn openssl(
|
pub fn openssl(
|
||||||
|
@ -225,7 +225,7 @@ mod openssl {
|
||||||
.map_err(TlsError::Tls)
|
.map_err(TlsError::Tls)
|
||||||
.map_init_err(|_| panic!()),
|
.map_init_err(|_| panic!()),
|
||||||
)
|
)
|
||||||
.and_then(|io: SslStream<TcpStream>| async {
|
.and_then(|io: TlsStream<TcpStream>| async {
|
||||||
let proto = if let Some(protos) = io.ssl().selected_alpn_protocol() {
|
let proto = if let Some(protos) = io.ssl().selected_alpn_protocol() {
|
||||||
if protos.windows(2).any(|window| window == b"h2") {
|
if protos.windows(2).any(|window| window == b"h2") {
|
||||||
Protocol::Http2
|
Protocol::Http2
|
||||||
|
|
|
@ -76,7 +76,7 @@ actix-http = { version = "3.0.0-beta.3", features = ["openssl"] }
|
||||||
actix-http-test = { version = "3.0.0-beta.2", features = ["openssl"] }
|
actix-http-test = { version = "3.0.0-beta.2", features = ["openssl"] }
|
||||||
actix-utils = "3.0.0-beta.1"
|
actix-utils = "3.0.0-beta.1"
|
||||||
actix-server = "2.0.0-beta.3"
|
actix-server = "2.0.0-beta.3"
|
||||||
actix-tls = { version = "3.0.0-beta.3", features = ["openssl", "rustls"] }
|
actix-tls = { version = "3.0.0-beta.4", features = ["openssl", "rustls"] }
|
||||||
|
|
||||||
brotli2 = "0.3.2"
|
brotli2 = "0.3.2"
|
||||||
flate2 = "1.0.13"
|
flate2 = "1.0.13"
|
||||||
|
|
152
src/route.rs
152
src/route.rs
|
@ -1,13 +1,13 @@
|
||||||
#![allow(clippy::rc_buffer)] // inner value is mutated before being shared (`Rc::get_mut`)
|
#![allow(clippy::rc_buffer)] // inner value is mutated before being shared (`Rc::get_mut`)
|
||||||
|
|
||||||
use std::future::Future;
|
use std::{future::Future, rc::Rc};
|
||||||
use std::pin::Pin;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
|
|
||||||
use actix_http::{http::Method, Error};
|
use actix_http::{http::Method, Error};
|
||||||
use actix_service::{Service, ServiceFactory};
|
use actix_service::{
|
||||||
use futures_util::future::{ready, FutureExt, LocalBoxFuture};
|
boxed::{self, BoxService, BoxServiceFactory},
|
||||||
|
Service, ServiceFactory,
|
||||||
|
};
|
||||||
|
use futures_core::future::LocalBoxFuture;
|
||||||
|
|
||||||
use crate::extract::FromRequest;
|
use crate::extract::FromRequest;
|
||||||
use crate::guard::{self, Guard};
|
use crate::guard::{self, Guard};
|
||||||
|
@ -16,33 +16,12 @@ use crate::responder::Responder;
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
use crate::HttpResponse;
|
use crate::HttpResponse;
|
||||||
|
|
||||||
type BoxedRouteService = Box<
|
|
||||||
dyn Service<
|
|
||||||
ServiceRequest,
|
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = Error,
|
|
||||||
Future = LocalBoxFuture<'static, Result<ServiceResponse, Error>>,
|
|
||||||
>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
type BoxedRouteNewService = Box<
|
|
||||||
dyn ServiceFactory<
|
|
||||||
ServiceRequest,
|
|
||||||
Config = (),
|
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = Error,
|
|
||||||
InitError = (),
|
|
||||||
Service = BoxedRouteService,
|
|
||||||
Future = LocalBoxFuture<'static, Result<BoxedRouteService, ()>>,
|
|
||||||
>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Resource route definition
|
/// Resource route definition
|
||||||
///
|
///
|
||||||
/// Route uses builder-like pattern for configuration.
|
/// Route uses builder-like pattern for configuration.
|
||||||
/// If handler is not explicitly set, default *404 Not Found* handler is used.
|
/// If handler is not explicitly set, default *404 Not Found* handler is used.
|
||||||
pub struct Route {
|
pub struct Route {
|
||||||
service: BoxedRouteNewService,
|
service: BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>,
|
||||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +30,7 @@ impl Route {
|
||||||
#[allow(clippy::new_without_default)]
|
#[allow(clippy::new_without_default)]
|
||||||
pub fn new() -> Route {
|
pub fn new() -> Route {
|
||||||
Route {
|
Route {
|
||||||
service: Box::new(RouteNewService::new(HandlerService::new(|| {
|
service: boxed::factory(HandlerService::new(HttpResponse::NotFound)),
|
||||||
ready(HttpResponse::NotFound())
|
|
||||||
}))),
|
|
||||||
guards: Rc::new(Vec::new()),
|
guards: Rc::new(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,44 +41,26 @@ impl Route {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServiceFactory<ServiceRequest> for Route {
|
impl ServiceFactory<ServiceRequest> for Route {
|
||||||
type Config = ();
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type Config = ();
|
||||||
type Service = RouteService;
|
type Service = RouteService;
|
||||||
type Future = CreateRouteService;
|
type InitError = ();
|
||||||
|
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: ()) -> Self::Future {
|
fn new_service(&self, _: ()) -> Self::Future {
|
||||||
CreateRouteService {
|
let fut = self.service.new_service(());
|
||||||
fut: self.service.new_service(()),
|
let guards = self.guards.clone();
|
||||||
guards: self.guards.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CreateRouteService {
|
Box::pin(async move {
|
||||||
fut: LocalBoxFuture<'static, Result<BoxedRouteService, ()>>,
|
let service = fut.await?;
|
||||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
Ok(RouteService { service, guards })
|
||||||
}
|
})
|
||||||
|
|
||||||
impl Future for CreateRouteService {
|
|
||||||
type Output = Result<RouteService, ()>;
|
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
||||||
let this = self.get_mut();
|
|
||||||
|
|
||||||
match this.fut.as_mut().poll(cx)? {
|
|
||||||
Poll::Ready(service) => Poll::Ready(Ok(RouteService {
|
|
||||||
service,
|
|
||||||
guards: this.guards.clone(),
|
|
||||||
})),
|
|
||||||
Poll::Pending => Poll::Pending,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RouteService {
|
pub struct RouteService {
|
||||||
service: BoxedRouteService,
|
service: BoxService<ServiceRequest, ServiceResponse, Error>,
|
||||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +80,7 @@ impl Service<ServiceRequest> for RouteService {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
actix_service::forward_ready!(service);
|
||||||
self.service.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||||
self.service.call(req)
|
self.service.call(req)
|
||||||
|
@ -224,80 +181,11 @@ impl Route {
|
||||||
R: Future + 'static,
|
R: Future + 'static,
|
||||||
R::Output: Responder + 'static,
|
R::Output: Responder + 'static,
|
||||||
{
|
{
|
||||||
self.service = Box::new(RouteNewService::new(HandlerService::new(handler)));
|
self.service = boxed::factory(HandlerService::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RouteNewService<T>
|
|
||||||
where
|
|
||||||
T: ServiceFactory<ServiceRequest, Error = Error>,
|
|
||||||
{
|
|
||||||
service: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> RouteNewService<T>
|
|
||||||
where
|
|
||||||
T: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error>,
|
|
||||||
T::Future: 'static,
|
|
||||||
T::Service: 'static,
|
|
||||||
<T::Service as Service<ServiceRequest>>::Future: 'static,
|
|
||||||
{
|
|
||||||
pub fn new(service: T) -> Self {
|
|
||||||
RouteNewService { service }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> ServiceFactory<ServiceRequest> for RouteNewService<T>
|
|
||||||
where
|
|
||||||
T: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error>,
|
|
||||||
T::Future: 'static,
|
|
||||||
T::Service: 'static,
|
|
||||||
<T::Service as Service<ServiceRequest>>::Future: 'static,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse;
|
|
||||||
type Error = Error;
|
|
||||||
type Config = ();
|
|
||||||
type Service = BoxedRouteService;
|
|
||||||
type InitError = ();
|
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
|
||||||
|
|
||||||
fn new_service(&self, _: ()) -> Self::Future {
|
|
||||||
self.service
|
|
||||||
.new_service(())
|
|
||||||
.map(|result| match result {
|
|
||||||
Ok(service) => {
|
|
||||||
let service = Box::new(RouteServiceWrapper { service }) as _;
|
|
||||||
Ok(service)
|
|
||||||
}
|
|
||||||
Err(_) => Err(()),
|
|
||||||
})
|
|
||||||
.boxed_local()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RouteServiceWrapper<T: Service<ServiceRequest>> {
|
|
||||||
service: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Service<ServiceRequest> for RouteServiceWrapper<T>
|
|
||||||
where
|
|
||||||
T::Future: 'static,
|
|
||||||
T: Service<ServiceRequest, Response = ServiceResponse, Error = Error>,
|
|
||||||
{
|
|
||||||
type Response = ServiceResponse;
|
|
||||||
type Error = Error;
|
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
|
||||||
|
|
||||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
self.service.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
|
||||||
Box::pin(self.service.call(req))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
|
@ -21,6 +21,7 @@ use flate2::{
|
||||||
Compression,
|
Compression,
|
||||||
};
|
};
|
||||||
use futures_util::ready;
|
use futures_util::ready;
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
use openssl::{
|
use openssl::{
|
||||||
pkey::PKey,
|
pkey::PKey,
|
||||||
ssl::{SslAcceptor, SslMethod},
|
ssl::{SslAcceptor, SslMethod},
|
||||||
|
@ -54,6 +55,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||||
Hello World Hello World Hello World Hello World Hello World \
|
Hello World Hello World Hello World Hello World Hello World \
|
||||||
Hello World Hello World Hello World Hello World Hello World";
|
Hello World Hello World Hello World Hello World Hello World";
|
||||||
|
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
fn openssl_config() -> SslAcceptor {
|
fn openssl_config() -> SslAcceptor {
|
||||||
let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_owned()]).unwrap();
|
let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.serialize_pem().unwrap();
|
let cert_file = cert.serialize_pem().unwrap();
|
||||||
|
@ -786,11 +788,6 @@ mod plus_rustls {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_reading_deflate_encoding_large_random_rustls() {
|
async fn test_reading_deflate_encoding_large_random_rustls() {
|
||||||
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
|
|
||||||
use rustls::{NoClientAuth, ServerConfig};
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::BufReader;
|
|
||||||
|
|
||||||
let data = rand::thread_rng()
|
let data = rand::thread_rng()
|
||||||
.sample_iter(&Alphanumeric)
|
.sample_iter(&Alphanumeric)
|
||||||
.take(160_000)
|
.take(160_000)
|
||||||
|
|
Loading…
Reference in New Issue