mirror of https://github.com/fafhrd91/actix-web
remove wrapper type for HttpServiceHandlerResponse
This commit is contained in:
parent
32d59ca904
commit
5cf907b5f4
|
@ -10,7 +10,7 @@ use actix_service::Service;
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// CloneableService might panic with some creative use of thread local storage.
|
/// CloneableService might panic with some creative use of thread local storage.
|
||||||
/// See https://github.com/actix/actix-web/issues/1295 for example
|
/// See https://github.com/actix/actix-web/issues/1295 for example
|
||||||
pub(crate) struct CloneableService<T: Service>(Rc<RefCell<T>>);
|
pub struct CloneableService<T: Service>(Rc<RefCell<T>>);
|
||||||
|
|
||||||
impl<T: Service> CloneableService<T> {
|
impl<T: Service> CloneableService<T> {
|
||||||
pub(crate) fn new(service: T) -> Self {
|
pub(crate) fn new(service: T) -> Self {
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl<'a> io::Write for Writer<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait DataFactory {
|
pub trait DataFactory {
|
||||||
fn set(&self, ext: &mut Extensions);
|
fn set(&self, ext: &mut Extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -570,41 +570,37 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
match proto {
|
match proto {
|
||||||
Protocol::Http2 => HttpServiceHandlerResponse {
|
Protocol::Http2 => HttpServiceHandlerResponse::H2Handshake(Some((
|
||||||
state: State::H2Handshake(Some((
|
server::handshake(io),
|
||||||
server::handshake(io),
|
self.cfg.clone(),
|
||||||
self.cfg.clone(),
|
self.srv.clone(),
|
||||||
self.srv.clone(),
|
deprecated_on_connect,
|
||||||
deprecated_on_connect,
|
connect_extensions,
|
||||||
connect_extensions,
|
peer_addr,
|
||||||
peer_addr,
|
))),
|
||||||
))),
|
Protocol::Http1 => HttpServiceHandlerResponse::H1(h1::Dispatcher::new(
|
||||||
},
|
io,
|
||||||
|
self.cfg.clone(),
|
||||||
Protocol::Http1 => HttpServiceHandlerResponse {
|
self.srv.clone(),
|
||||||
state: State::H1(h1::Dispatcher::new(
|
self.expect.clone(),
|
||||||
io,
|
self.upgrade.clone(),
|
||||||
self.cfg.clone(),
|
deprecated_on_connect,
|
||||||
self.srv.clone(),
|
connect_extensions,
|
||||||
self.expect.clone(),
|
peer_addr,
|
||||||
self.upgrade.clone(),
|
)),
|
||||||
deprecated_on_connect,
|
|
||||||
connect_extensions,
|
|
||||||
peer_addr,
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project(project = StateProj)]
|
#[pin_project(project = StateProj)]
|
||||||
enum State<T, S, B, X, U>
|
pub enum HttpServiceHandlerResponse<T, S, B, X, U>
|
||||||
where
|
where
|
||||||
S: Service<Request = Request>,
|
|
||||||
S::Future: 'static,
|
|
||||||
S::Error: Into<Error>,
|
|
||||||
T: AsyncRead + AsyncWrite + Unpin,
|
T: AsyncRead + AsyncWrite + Unpin,
|
||||||
B: MessageBody,
|
S: Service<Request = Request>,
|
||||||
|
S::Error: Into<Error> + 'static,
|
||||||
|
S::Future: 'static,
|
||||||
|
S::Response: Into<Response<B>> + 'static,
|
||||||
|
B: MessageBody + 'static,
|
||||||
X: Service<Request = Request, Response = Request>,
|
X: Service<Request = Request, Response = Request>,
|
||||||
X::Error: Into<Error>,
|
X::Error: Into<Error>,
|
||||||
U: Service<Request = (Request, Framed<T, h1::Codec>), Response = ()>,
|
U: Service<Request = (Request, Framed<T, h1::Codec>), Response = ()>,
|
||||||
|
@ -624,24 +620,6 @@ where
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
|
||||||
pub struct HttpServiceHandlerResponse<T, S, B, X, U>
|
|
||||||
where
|
|
||||||
T: AsyncRead + AsyncWrite + Unpin,
|
|
||||||
S: Service<Request = Request>,
|
|
||||||
S::Error: Into<Error> + 'static,
|
|
||||||
S::Future: 'static,
|
|
||||||
S::Response: Into<Response<B>> + 'static,
|
|
||||||
B: MessageBody + 'static,
|
|
||||||
X: Service<Request = Request, Response = Request>,
|
|
||||||
X::Error: Into<Error>,
|
|
||||||
U: Service<Request = (Request, Framed<T, h1::Codec>), Response = ()>,
|
|
||||||
U::Error: fmt::Display,
|
|
||||||
{
|
|
||||||
#[pin]
|
|
||||||
state: State<T, S, B, X, U>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, S, B, X, U> Future for HttpServiceHandlerResponse<T, S, B, X, U>
|
impl<T, S, B, X, U> Future for HttpServiceHandlerResponse<T, S, B, X, U>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite + Unpin,
|
T: AsyncRead + AsyncWrite + Unpin,
|
||||||
|
@ -657,27 +635,7 @@ where
|
||||||
{
|
{
|
||||||
type Output = Result<(), DispatchError>;
|
type Output = Result<(), DispatchError>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
self.project().state.poll(cx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, S, B, X, U> State<T, S, B, X, U>
|
|
||||||
where
|
|
||||||
T: AsyncRead + AsyncWrite + Unpin,
|
|
||||||
S: Service<Request = Request>,
|
|
||||||
S::Error: Into<Error> + 'static,
|
|
||||||
S::Response: Into<Response<B>> + 'static,
|
|
||||||
B: MessageBody + 'static,
|
|
||||||
X: Service<Request = Request, Response = Request>,
|
|
||||||
X::Error: Into<Error>,
|
|
||||||
U: Service<Request = (Request, Framed<T, h1::Codec>), Response = ()>,
|
|
||||||
U::Error: fmt::Display,
|
|
||||||
{
|
|
||||||
fn poll(
|
|
||||||
mut self: Pin<&mut Self>,
|
|
||||||
cx: &mut Context<'_>,
|
|
||||||
) -> Poll<Result<(), DispatchError>> {
|
|
||||||
match self.as_mut().project() {
|
match self.as_mut().project() {
|
||||||
StateProj::H1(disp) => disp.poll(cx),
|
StateProj::H1(disp) => disp.poll(cx),
|
||||||
StateProj::H2(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) =
|
let (_, cfg, srv, on_connect, on_connect_data, peer_addr) =
|
||||||
data.take().unwrap();
|
data.take().unwrap();
|
||||||
self.set(State::H2(Dispatcher::new(
|
self.set(HttpServiceHandlerResponse::H2(Dispatcher::new(
|
||||||
srv,
|
srv,
|
||||||
conn,
|
conn,
|
||||||
on_connect,
|
on_connect,
|
||||||
|
|
Loading…
Reference in New Issue