mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into feature/h1_pending_timer
This commit is contained in:
commit
b87cfd5c6a
|
@ -1,14 +1,12 @@
|
|||
name: Upload documentation
|
||||
name: Upload Documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'actix/actix-web'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -20,14 +18,14 @@ jobs:
|
|||
profile: minimal
|
||||
override: true
|
||||
|
||||
- name: check build
|
||||
- name: Build Docs
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: doc
|
||||
args: --workspace --all-features --no-deps
|
||||
|
||||
- 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
|
||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||
|
|
|
@ -66,7 +66,7 @@ required-features = ["compress"]
|
|||
|
||||
[[test]]
|
||||
name = "test_server"
|
||||
required-features = ["compress"]
|
||||
required-features = ["compress", "cookies"]
|
||||
|
||||
[[example]]
|
||||
name = "on_connect"
|
||||
|
@ -80,11 +80,11 @@ required-features = ["rustls"]
|
|||
actix-codec = "0.4.0-beta.1"
|
||||
actix-macros = "0.2.0"
|
||||
actix-router = "0.2.7"
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
actix-server = "2.0.0-beta.3"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
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-http = "3.0.0-beta.3"
|
||||
|
|
|
@ -33,5 +33,5 @@ mime_guess = "2.0.1"
|
|||
percent-encoding = "2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
actix-web = "4.0.0-beta.3"
|
||||
|
|
|
@ -31,9 +31,9 @@ openssl = ["tls-openssl", "awc/openssl"]
|
|||
[dependencies]
|
||||
actix-service = "2.0.0-beta.4"
|
||||
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-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
actix-server = "2.0.0-beta.3"
|
||||
awc = { version = "3.0.0-beta.2", default-features = false }
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ trust-dns = ["trust-dns-resolver"]
|
|||
actix-service = "2.0.0-beta.4"
|
||||
actix-codec = "0.4.0-beta.1"
|
||||
actix-utils = "3.0.0-beta.2"
|
||||
actix-rt = "2"
|
||||
actix-tls = "3.0.0-beta.2"
|
||||
actix-rt = "2.1"
|
||||
actix-tls = "3.0.0-beta.4"
|
||||
|
||||
ahash = "0.7"
|
||||
base64 = "0.13"
|
||||
|
@ -61,12 +61,12 @@ derive_more = "0.99.5"
|
|||
encoding_rs = "0.8"
|
||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
|
||||
h2 = "0.3.0"
|
||||
h2 = "=0.3.0"
|
||||
http = "0.2.2"
|
||||
httparse = "1.3"
|
||||
itoa = "0.4"
|
||||
language-tags = "0.2"
|
||||
lazy_static = "1.4"
|
||||
once_cell = "1.5"
|
||||
log = "0.4"
|
||||
mime = "0.3"
|
||||
percent-encoding = "2.1"
|
||||
|
@ -90,7 +90,7 @@ trust-dns-resolver = { version = "0.20.0", optional = true }
|
|||
[dev-dependencies]
|
||||
actix-server = "2.0.0-beta.3"
|
||||
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"
|
||||
env_logger = "0.8"
|
||||
rcgen = "0.8"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::net::IpAddr;
|
||||
use std::time::Duration;
|
||||
|
||||
const DEFAULT_H2_CONN_WINDOW: u32 = 1024 * 1024 * 2; // 2MB
|
||||
|
@ -13,6 +14,7 @@ pub(crate) struct ConnectorConfig {
|
|||
pub(crate) limit: usize,
|
||||
pub(crate) conn_window_size: u32,
|
||||
pub(crate) stream_window_size: u32,
|
||||
pub(crate) local_address: Option<IpAddr>,
|
||||
}
|
||||
|
||||
impl Default for ConnectorConfig {
|
||||
|
@ -25,6 +27,7 @@ impl Default for ConnectorConfig {
|
|||
limit: 100,
|
||||
conn_window_size: DEFAULT_H2_CONN_WINDOW,
|
||||
stream_window_size: DEFAULT_H2_STREAM_WINDOW,
|
||||
local_address: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
fmt,
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
net::IpAddr,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_rt::net::TcpStream;
|
||||
|
@ -240,6 +243,12 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Set local IP Address the connector would use for establishing connection.
|
||||
pub fn local_address(mut self, addr: IpAddr) -> Self {
|
||||
self.config.local_address = Some(addr);
|
||||
self
|
||||
}
|
||||
|
||||
/// Finish configuration process and create connector service.
|
||||
/// The Connector builder always concludes by calling `finish()` last in
|
||||
/// its combinator chain.
|
||||
|
@ -247,10 +256,19 @@ where
|
|||
self,
|
||||
) -> impl Service<Connect, Response = impl Connection, Error = ConnectError> + Clone
|
||||
{
|
||||
let local_address = self.config.local_address;
|
||||
let timeout = self.config.timeout;
|
||||
|
||||
let tcp_service = TimeoutService::new(
|
||||
self.config.timeout,
|
||||
apply_fn(self.connector.clone(), |msg: Connect, srv| {
|
||||
srv.call(TcpConnect::new(msg.uri).set_addr(msg.addr))
|
||||
timeout,
|
||||
apply_fn(self.connector.clone(), move |msg: Connect, srv| {
|
||||
let mut req = TcpConnect::new(msg.uri).set_addr(msg.addr);
|
||||
|
||||
if let Some(local_addr) = local_address {
|
||||
req = req.set_local_addr(local_addr);
|
||||
}
|
||||
|
||||
srv.call(req)
|
||||
})
|
||||
.map_err(ConnectError::from)
|
||||
.map(|stream| (stream.into_parts().0, Protocol::Http1)),
|
||||
|
@ -294,10 +312,16 @@ where
|
|||
use actix_tls::connect::ssl::rustls::{RustlsConnector, Session};
|
||||
|
||||
let ssl_service = TimeoutService::new(
|
||||
self.config.timeout,
|
||||
timeout,
|
||||
pipeline(
|
||||
apply_fn(self.connector.clone(), |msg: Connect, srv| {
|
||||
srv.call(TcpConnect::new(msg.uri).set_addr(msg.addr))
|
||||
apply_fn(self.connector.clone(), move |msg: Connect, srv| {
|
||||
let mut req = TcpConnect::new(msg.uri).set_addr(msg.addr);
|
||||
|
||||
if let Some(local_addr) = local_address {
|
||||
req = req.set_local_addr(local_addr);
|
||||
}
|
||||
|
||||
srv.call(req)
|
||||
})
|
||||
.map_err(ConnectError::from),
|
||||
)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//! Browser conformance tests at: http://greenbytes.de/tech/tc2231/
|
||||
//! IANA assignment: http://www.iana.org/assignments/cont-disp/cont-disp.xhtml
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
|
@ -520,9 +520,7 @@ impl fmt::Display for DispositionParam {
|
|||
//
|
||||
//
|
||||
// See also comments in test_from_raw_unnecessary_percent_decode.
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new("[\x00-\x08\x10-\x1F\x7F\"\\\\]").unwrap();
|
||||
}
|
||||
static RE: Lazy<Regex> = Lazy::new(|| Regex::new("[\x00-\x08\x10-\x1F\x7F\"\\\\]").unwrap());
|
||||
match self {
|
||||
DispositionParam::Name(ref value) => write!(f, "name={}", value),
|
||||
DispositionParam::Filename(ref value) => {
|
||||
|
|
|
@ -28,7 +28,7 @@ mime = "0.3"
|
|||
twoway = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
actix-http = "3.0.0-beta.3"
|
||||
tokio = { version = "1", features = ["sync"] }
|
||||
tokio-stream = "0.1"
|
||||
|
|
|
@ -28,6 +28,6 @@ pin-project = "1.0.0"
|
|||
tokio = { version = "1", features = ["sync"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
env_logger = "0.8"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
|
|
|
@ -19,7 +19,7 @@ syn = { version = "1", features = ["full", "parsing"] }
|
|||
proc-macro2 = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
actix-web = "4.0.0-beta.3"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
trybuild = "1"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
## Unreleased - 2021-xx-xx
|
||||
### Added
|
||||
* `ClientResponse::timeout` for set the timeout of collecting response body. [#1931]
|
||||
* `ClientBuilder::local_address` for bind to a local ip address for this client. [#2024]
|
||||
|
||||
### Changed
|
||||
* Feature `cookies` is now optional and enabled by default. [#1981]
|
||||
|
@ -15,6 +16,7 @@
|
|||
[#1931]: https://github.com/actix/actix-web/pull/1931
|
||||
[#1981]: https://github.com/actix/actix-web/pull/1981
|
||||
[#2008]: https://github.com/actix/actix-web/pull/2008
|
||||
[#2024]: https://github.com/actix/actix-web/pull/2024
|
||||
|
||||
## 3.0.0-beta.2 - 2021-02-10
|
||||
### Added
|
||||
|
|
|
@ -47,7 +47,7 @@ trust-dns = ["actix-http/trust-dns"]
|
|||
actix-codec = "0.4.0-beta.1"
|
||||
actix-service = "2.0.0-beta.4"
|
||||
actix-http = "3.0.0-beta.3"
|
||||
actix-rt = "2"
|
||||
actix-rt = "2.1"
|
||||
|
||||
base64 = "0.13"
|
||||
bytes = "1"
|
||||
|
@ -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-utils = "3.0.0-beta.1"
|
||||
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"
|
||||
flate2 = "1.0.13"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::net::IpAddr;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
|
@ -25,6 +26,7 @@ pub struct ClientBuilder<T = (), U = ()> {
|
|||
conn_window_size: Option<u32>,
|
||||
headers: HeaderMap,
|
||||
timeout: Option<Duration>,
|
||||
local_address: Option<IpAddr>,
|
||||
connector: Connector<T, U>,
|
||||
}
|
||||
|
||||
|
@ -42,6 +44,7 @@ impl ClientBuilder {
|
|||
default_headers: true,
|
||||
headers: HeaderMap::new(),
|
||||
timeout: Some(Duration::from_secs(5)),
|
||||
local_address: None,
|
||||
connector: Connector::new(),
|
||||
max_http_version: None,
|
||||
stream_window_size: None,
|
||||
|
@ -72,6 +75,7 @@ where
|
|||
default_headers: self.default_headers,
|
||||
headers: self.headers,
|
||||
timeout: self.timeout,
|
||||
local_address: None,
|
||||
connector,
|
||||
max_http_version: self.max_http_version,
|
||||
stream_window_size: self.stream_window_size,
|
||||
|
@ -94,6 +98,12 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Set local IP Address the connector would use for establishing connection.
|
||||
pub fn local_address(mut self, addr: IpAddr) -> Self {
|
||||
self.local_address = Some(addr);
|
||||
self
|
||||
}
|
||||
|
||||
/// Maximum supported HTTP major version.
|
||||
///
|
||||
/// Supported versions are HTTP/1.1 and HTTP/2.
|
||||
|
@ -184,6 +194,9 @@ where
|
|||
if let Some(val) = self.stream_window_size {
|
||||
connector = connector.initial_window_size(val)
|
||||
};
|
||||
if let Some(val) = self.local_address {
|
||||
connector = connector.local_address(val);
|
||||
}
|
||||
|
||||
let config = ClientConfig {
|
||||
headers: self.headers,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
@ -871,3 +872,34 @@ async fn client_bearer_auth() {
|
|||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_local_address() {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||
|
||||
let srv = test::start(move || {
|
||||
App::new().service(web::resource("/").route(web::to(
|
||||
move |req: HttpRequest| async move {
|
||||
assert_eq!(req.peer_addr().unwrap().ip(), ip);
|
||||
Ok::<_, Error>(HttpResponse::Ok())
|
||||
},
|
||||
)))
|
||||
});
|
||||
let client = awc::Client::builder().local_address(ip).finish();
|
||||
|
||||
let res = client.get(srv.url("/")).send().await.unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
|
||||
let client = awc::Client::builder()
|
||||
.connector(
|
||||
// connector local address setting should always be override by client builder.
|
||||
awc::Connector::new().local_address(IpAddr::V4(Ipv4Addr::new(128, 0, 0, 1))),
|
||||
)
|
||||
.local_address(ip)
|
||||
.finish();
|
||||
|
||||
let res = client.get(srv.url("/")).send().await.unwrap();
|
||||
|
||||
assert_eq!(res.status(), 200);
|
||||
}
|
||||
|
|
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`)
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::{future::Future, rc::Rc};
|
||||
|
||||
use actix_http::{http::Method, Error};
|
||||
use actix_service::{Service, ServiceFactory};
|
||||
use futures_util::future::{ready, FutureExt, LocalBoxFuture};
|
||||
use actix_service::{
|
||||
boxed::{self, BoxService, BoxServiceFactory},
|
||||
Service, ServiceFactory,
|
||||
};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
|
||||
use crate::extract::FromRequest;
|
||||
use crate::guard::{self, Guard};
|
||||
|
@ -16,33 +16,12 @@ use crate::responder::Responder;
|
|||
use crate::service::{ServiceRequest, ServiceResponse};
|
||||
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
|
||||
///
|
||||
/// Route uses builder-like pattern for configuration.
|
||||
/// If handler is not explicitly set, default *404 Not Found* handler is used.
|
||||
pub struct Route {
|
||||
service: BoxedRouteNewService,
|
||||
service: BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
|
@ -51,9 +30,7 @@ impl Route {
|
|||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Route {
|
||||
Route {
|
||||
service: Box::new(RouteNewService::new(HandlerService::new(|| {
|
||||
ready(HttpResponse::NotFound())
|
||||
}))),
|
||||
service: boxed::factory(HandlerService::new(HttpResponse::NotFound)),
|
||||
guards: Rc::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
@ -64,44 +41,26 @@ impl Route {
|
|||
}
|
||||
|
||||
impl ServiceFactory<ServiceRequest> for Route {
|
||||
type Config = ();
|
||||
type Response = ServiceResponse;
|
||||
type Error = Error;
|
||||
type InitError = ();
|
||||
type Config = ();
|
||||
type Service = RouteService;
|
||||
type Future = CreateRouteService;
|
||||
type InitError = ();
|
||||
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
||||
|
||||
fn new_service(&self, _: ()) -> Self::Future {
|
||||
CreateRouteService {
|
||||
fut: self.service.new_service(()),
|
||||
guards: self.guards.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
let fut = self.service.new_service(());
|
||||
let guards = self.guards.clone();
|
||||
|
||||
pub struct CreateRouteService {
|
||||
fut: LocalBoxFuture<'static, Result<BoxedRouteService, ()>>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
Box::pin(async move {
|
||||
let service = fut.await?;
|
||||
Ok(RouteService { service, guards })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RouteService {
|
||||
service: BoxedRouteService,
|
||||
service: BoxService<ServiceRequest, ServiceResponse, Error>,
|
||||
guards: Rc<Vec<Box<dyn Guard>>>,
|
||||
}
|
||||
|
||||
|
@ -121,9 +80,7 @@ impl Service<ServiceRequest> for RouteService {
|
|||
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)
|
||||
}
|
||||
actix_service::forward_ready!(service);
|
||||
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
self.service.call(req)
|
||||
|
@ -224,80 +181,11 @@ impl Route {
|
|||
R: Future + 'static,
|
||||
R::Output: Responder + 'static,
|
||||
{
|
||||
self.service = Box::new(RouteNewService::new(HandlerService::new(handler)));
|
||||
self.service = boxed::factory(HandlerService::new(handler));
|
||||
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)]
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
|
|
|
@ -21,6 +21,7 @@ use flate2::{
|
|||
Compression,
|
||||
};
|
||||
use futures_util::ready;
|
||||
#[cfg(feature = "openssl")]
|
||||
use openssl::{
|
||||
pkey::PKey,
|
||||
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";
|
||||
|
||||
#[cfg(feature = "openssl")]
|
||||
fn openssl_config() -> SslAcceptor {
|
||||
let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.serialize_pem().unwrap();
|
||||
|
@ -786,11 +788,6 @@ mod plus_rustls {
|
|||
|
||||
#[actix_rt::test]
|
||||
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()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(160_000)
|
||||
|
|
Loading…
Reference in New Issue