From 5cf907b5f4f03f2cab8ad0162268744457cc4ec1 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Tue, 1 Dec 2020 07:50:59 +0800 Subject: [PATCH] remove wrapper type for HttpServiceHandlerResponse --- actix-http/src/cloneable.rs | 2 +- actix-http/src/helpers.rs | 2 +- actix-http/src/service.rs | 94 ++++++++++--------------------------- 3 files changed, 28 insertions(+), 70 deletions(-) diff --git a/actix-http/src/cloneable.rs b/actix-http/src/cloneable.rs index b64c299fc..8c90e629c 100644 --- a/actix-http/src/cloneable.rs +++ b/actix-http/src/cloneable.rs @@ -10,7 +10,7 @@ use actix_service::Service; /// # Panics /// CloneableService might panic with some creative use of thread local storage. /// See https://github.com/actix/actix-web/issues/1295 for example -pub(crate) struct CloneableService(Rc>); +pub struct CloneableService(Rc>); impl CloneableService { pub(crate) fn new(service: T) -> Self { diff --git a/actix-http/src/helpers.rs b/actix-http/src/helpers.rs index ac0e0f118..45e5249c0 100644 --- a/actix-http/src/helpers.rs +++ b/actix-http/src/helpers.rs @@ -56,7 +56,7 @@ impl<'a> io::Write for Writer<'a> { } } -pub(crate) trait DataFactory { +pub trait DataFactory { fn set(&self, ext: &mut Extensions); } diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 75745209c..8852a015b 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -570,41 +570,37 @@ where } match proto { - Protocol::Http2 => HttpServiceHandlerResponse { - state: State::H2Handshake(Some(( - server::handshake(io), - self.cfg.clone(), - self.srv.clone(), - deprecated_on_connect, - connect_extensions, - peer_addr, - ))), - }, - - Protocol::Http1 => HttpServiceHandlerResponse { - state: State::H1(h1::Dispatcher::new( - io, - self.cfg.clone(), - self.srv.clone(), - self.expect.clone(), - self.upgrade.clone(), - deprecated_on_connect, - connect_extensions, - peer_addr, - )), - }, + Protocol::Http2 => HttpServiceHandlerResponse::H2Handshake(Some(( + server::handshake(io), + self.cfg.clone(), + self.srv.clone(), + deprecated_on_connect, + connect_extensions, + peer_addr, + ))), + Protocol::Http1 => HttpServiceHandlerResponse::H1(h1::Dispatcher::new( + io, + self.cfg.clone(), + self.srv.clone(), + self.expect.clone(), + self.upgrade.clone(), + deprecated_on_connect, + connect_extensions, + peer_addr, + )), } } } #[pin_project(project = StateProj)] -enum State +pub enum HttpServiceHandlerResponse where - S: Service, - S::Future: 'static, - S::Error: Into, T: AsyncRead + AsyncWrite + Unpin, - B: MessageBody, + S: Service, + S::Error: Into + 'static, + S::Future: 'static, + S::Response: Into> + 'static, + B: MessageBody + 'static, X: Service, X::Error: Into, U: Service), Response = ()>, @@ -624,24 +620,6 @@ where ), } -#[pin_project] -pub struct HttpServiceHandlerResponse -where - T: AsyncRead + AsyncWrite + Unpin, - S: Service, - S::Error: Into + 'static, - S::Future: 'static, - S::Response: Into> + 'static, - B: MessageBody + 'static, - X: Service, - X::Error: Into, - U: Service), Response = ()>, - U::Error: fmt::Display, -{ - #[pin] - state: State, -} - impl Future for HttpServiceHandlerResponse where T: AsyncRead + AsyncWrite + Unpin, @@ -657,27 +635,7 @@ where { type Output = Result<(), DispatchError>; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.project().state.poll(cx) - } -} - -impl State -where - T: AsyncRead + AsyncWrite + Unpin, - S: Service, - S::Error: Into + 'static, - S::Response: Into> + 'static, - B: MessageBody + 'static, - X: Service, - X::Error: Into, - U: Service), Response = ()>, - U::Error: fmt::Display, -{ - fn poll( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match self.as_mut().project() { StateProj::H1(disp) => disp.poll(cx), StateProj::H2(disp) => disp.poll(cx), @@ -696,7 +654,7 @@ where }; let (_, cfg, srv, on_connect, on_connect_data, peer_addr) = data.take().unwrap(); - self.set(State::H2(Dispatcher::new( + self.set(HttpServiceHandlerResponse::H2(Dispatcher::new( srv, conn, on_connect,