http errors are into<response>

This commit is contained in:
Rob Ede 2021-04-19 23:18:00 +01:00
parent 427fe6bd82
commit a0daecfda5
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
9 changed files with 170 additions and 156 deletions

View File

@ -5,9 +5,8 @@ use std::{fmt, net};
use actix_codec::Framed;
use actix_service::{IntoServiceFactory, Service, ServiceFactory};
use crate::body::MessageBody;
use crate::body::{Body, MessageBody};
use crate::config::{KeepAlive, ServiceConfig};
use crate::error::Error;
use crate::h1::{Codec, ExpectHandler, H1Service, UpgradeHandler};
use crate::h2::H2Service;
use crate::request::Request;
@ -34,7 +33,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler> {
impl<T, S> HttpServiceBuilder<T, S, ExpectHandler, UpgradeHandler>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
<S::Service as Service<Request>>::Future: 'static,
{
@ -57,11 +56,11 @@ where
impl<T, S, X, U> HttpServiceBuilder<T, S, X, U>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
<S::Service as Service<Request>>::Future: 'static,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<(Request, Framed<T, Codec>), Config = (), Response = ()>,
U::Error: fmt::Display,
@ -123,7 +122,7 @@ where
where
F: IntoServiceFactory<X1, Request>,
X1: ServiceFactory<Request, Config = (), Response = Request>,
X1::Error: Into<Error>,
X1::Error: Into<Response<Body>>,
X1::InitError: fmt::Debug,
{
HttpServiceBuilder {
@ -181,7 +180,7 @@ where
where
B: MessageBody,
F: IntoServiceFactory<S, Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>>,
{
@ -204,7 +203,7 @@ where
where
B: MessageBody + 'static,
F: IntoServiceFactory<S, Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
{
@ -225,7 +224,7 @@ where
where
B: MessageBody + 'static,
F: IntoServiceFactory<S, Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
{

View File

@ -111,7 +111,7 @@ impl From<std::convert::Infallible> for Error {
}
}
/// Convert `Error` to a `Response` instance
/// Convert `Error` to a `Response` instance.
impl From<Error> for Response<Body> {
fn from(err: Error) -> Self {
Response::from_error(err)

View File

@ -17,19 +17,22 @@ use futures_core::ready;
use log::{error, trace};
use pin_project::pin_project;
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
use crate::config::ServiceConfig;
use crate::error::{DispatchError, Error};
use crate::error::{ParseError, PayloadError};
use crate::http::StatusCode;
use crate::request::Request;
use crate::response::Response;
use crate::service::HttpFlow;
use crate::OnConnectData;
use crate::{
body::{Body, BodySize, MessageBody, ResponseBody},
config::ServiceConfig,
error::{DispatchError, ParseError, PayloadError},
http::StatusCode,
request::Request,
response::Response,
service::HttpFlow,
OnConnectData,
};
use super::codec::Codec;
use super::payload::{Payload, PayloadSender, PayloadStatus};
use super::{Message, MessageType};
use super::{
codec::Codec,
payload::{Payload, PayloadSender, PayloadStatus},
Message, MessageType,
};
const LW_BUFFER_SIZE: usize = 1024;
const HW_BUFFER_SIZE: usize = 1024 * 8;
@ -50,10 +53,10 @@ bitflags! {
pub struct Dispatcher<T, S, B, X, U>
where
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -68,10 +71,10 @@ where
enum DispatcherState<T, S, B, X, U>
where
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -83,10 +86,10 @@ where
struct InnerDispatcher<T, S, B, X, U>
where
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -151,11 +154,11 @@ impl<T, S, B, X, U> Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -207,11 +210,11 @@ impl<T, S, B, X, U> InnerDispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -347,7 +350,7 @@ where
// send service call error as response
Poll::Ready(Err(err)) => {
let res = Response::from_error(err.into());
let res: Response<Body> = err.into();
let (res, body) = res.replace_body(());
self.as_mut().send_response(res, body.into_body())?;
}
@ -408,7 +411,7 @@ where
}
// send expect error as response
Poll::Ready(Err(err)) => {
let res = Response::from_error(err.into());
let res: Response<Body> = err.into();
let (res, body) = res.replace_body(());
self.as_mut().send_response(res, body.into_body())?;
}
@ -457,7 +460,7 @@ where
// to notify the dispatcher a new state is set and the outer loop
// should be continue.
Poll::Ready(Err(err)) => {
let res = Response::from_error(err.into());
let res: Response<Body> = err.into();
let (res, body) = res.replace_body(());
return self.send_response(res, body.into_body());
}
@ -477,7 +480,7 @@ where
Poll::Pending => Ok(()),
// see the comment on ExpectCall state branch's Ready(Err(err)).
Poll::Ready(Err(err)) => {
let res = Response::from_error(err.into());
let res: Response<Body> = err.into();
let (res, body) = res.replace_body(());
self.send_response(res, body.into_body())
}
@ -818,11 +821,11 @@ impl<T, S, B, X, U> Future for Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display,
{

View File

@ -1,7 +1,10 @@
use std::marker::PhantomData;
use std::rc::Rc;
use std::task::{Context, Poll};
use std::{fmt, net};
use std::{
fmt,
marker::PhantomData,
net,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_rt::net::TcpStream;
@ -10,18 +13,17 @@ use actix_service::{
};
use actix_utils::future::ready;
use futures_core::future::LocalBoxFuture;
use log::error;
use crate::body::MessageBody;
use crate::config::ServiceConfig;
use crate::error::{DispatchError, Error};
use crate::request::Request;
use crate::response::Response;
use crate::service::HttpServiceHandler;
use crate::{ConnectCallback, OnConnectData};
use crate::{
body::{Body, MessageBody},
config::ServiceConfig,
error::DispatchError,
service::HttpServiceHandler,
ConnectCallback, OnConnectData, Request, Response,
};
use super::codec::Codec;
use super::dispatcher::Dispatcher;
use super::{ExpectHandler, UpgradeHandler};
use super::{codec::Codec, dispatcher::Dispatcher, ExpectHandler, UpgradeHandler};
/// `ServiceFactory` implementation for HTTP1 transport
pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> {
@ -36,7 +38,7 @@ pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> {
impl<T, S, B> H1Service<T, S, B>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody,
@ -61,17 +63,17 @@ impl<S, B, X, U> H1Service<TcpStream, S, B, X, U>
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<(Request, Framed<TcpStream, Codec>), Config = (), Response = ()>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create simple tcp stream service
@ -106,13 +108,13 @@ mod openssl {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<
(Request, Framed<TlsStream<TcpStream>, Codec>),
@ -120,7 +122,7 @@ mod openssl {
Response = (),
>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create openssl based service
@ -162,13 +164,13 @@ mod rustls {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<
(Request, Framed<TlsStream<TcpStream>, Codec>),
@ -176,7 +178,7 @@ mod rustls {
Response = (),
>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create rustls based service
@ -205,7 +207,7 @@ mod rustls {
impl<T, S, B, X, U> H1Service<T, S, B, X, U>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
S::InitError: fmt::Debug,
B: MessageBody,
@ -213,7 +215,7 @@ where
pub fn expect<X1>(self, expect: X1) -> H1Service<T, S, B, X1, U>
where
X1: ServiceFactory<Request, Response = Request>,
X1::Error: Into<Error>,
X1::Error: Into<Response<Body>>,
X1::InitError: fmt::Debug,
{
H1Service {
@ -255,17 +257,17 @@ where
T: AsyncRead + AsyncWrite + Unpin + 'static,
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
S::InitError: fmt::Debug,
B: MessageBody,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<(Request, Framed<T, Codec>), Config = (), Response = ()>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
type Response = ();
@ -285,12 +287,12 @@ where
Box::pin(async move {
let expect = expect
.await
.map_err(|e| log::error!("Init http expect service error: {:?}", e))?;
.map_err(|e| error!("Init http expect service error: {:?}", e))?;
let upgrade = match upgrade {
Some(upgrade) => {
let upgrade = upgrade.await.map_err(|e| {
log::error!("Init http upgrade service error: {:?}", e)
error!("Init http upgrade service error: {:?}", e)
})?;
Some(upgrade)
}
@ -299,7 +301,7 @@ where
let service = service
.await
.map_err(|e| log::error!("Init http service error: {:?}", e))?;
.map_err(|e| error!("Init http service error: {:?}", e))?;
Ok(H1ServiceHandler::new(
cfg,
@ -320,22 +322,22 @@ impl<T, S, B, X, U> Service<(T, Option<net::SocketAddr>)>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
{
type Response = ();
type Error = DispatchError;
type Future = Dispatcher<T, S, B, X, U>;
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self._poll_ready(cx).map_err(|e| {
log::error!("HTTP/1 service readiness error: {:?}", e);
DispatchError::Service(e)
self._poll_ready(cx).map_err(|err| {
error!("HTTP/1 service readiness error: {:?}", err);
DispatchError::Service(err)
})
}

View File

@ -1,5 +1,12 @@
use std::task::{Context, Poll};
use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc};
use std::{
cmp,
future::Future,
marker::PhantomData,
net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_service::Service;
@ -12,15 +19,14 @@ use h2::{
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
use log::{error, trace};
use crate::body::{BodySize, MessageBody, ResponseBody};
use crate::config::ServiceConfig;
use crate::error::{DispatchError, Error};
use crate::message::ResponseHead;
use crate::payload::Payload;
use crate::request::Request;
use crate::response::Response;
use crate::service::HttpFlow;
use crate::OnConnectData;
use crate::{
body::{Body, BodySize, MessageBody, ResponseBody},
config::ServiceConfig,
error::DispatchError,
payload::Payload,
service::HttpFlow,
OnConnectData, Request, Response, ResponseHead,
};
const CHUNK_SIZE: usize = 16_384;
@ -44,7 +50,7 @@ impl<T, S, B, X, U> Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
S::Response: Into<Response<B>>,
B: MessageBody,
{
@ -70,7 +76,7 @@ impl<T, S, B, X, U> Future for Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
@ -138,7 +144,7 @@ enum ServiceResponseState<F, B> {
impl<F, I, E, B> ServiceResponse<F, I, E, B>
where
F: Future<Output = Result<I, E>>,
E: Into<Error>,
E: Into<Response<Body>>,
I: Into<Response<B>>,
B: MessageBody,
{
@ -214,7 +220,7 @@ where
impl<F, I, E, B> Future for ServiceResponse<F, I, E, B>
where
F: Future<Output = Result<I, E>>,
E: Into<Error>,
E: Into<Response<Body>>,
I: Into<Response<B>>,
B: MessageBody,
{
@ -253,7 +259,7 @@ where
}
Err(err) => {
let res = Response::from_error(err.into());
let res: Response<Body> = err.into();
let (res, body) = res.replace_body(());
let mut send = send.take().unwrap();

View File

@ -1,8 +1,11 @@
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{net, rc::Rc};
use std::{
future::Future,
marker::PhantomData,
net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::net::TcpStream;
@ -16,13 +19,15 @@ use futures_core::{future::LocalBoxFuture, ready};
use h2::server::{handshake, Handshake};
use log::error;
use crate::body::MessageBody;
use crate::config::ServiceConfig;
use crate::error::{DispatchError, Error};
use crate::request::Request;
use crate::response::Response;
use crate::service::HttpFlow;
use crate::{ConnectCallback, OnConnectData};
use crate::{
body::{Body, MessageBody},
config::ServiceConfig,
error::DispatchError,
request::Request,
response::Response,
service::HttpFlow,
ConnectCallback, Error, OnConnectData,
};
use super::dispatcher::Dispatcher;
@ -37,7 +42,7 @@ pub struct H2Service<T, S, B> {
impl<T, S, B> H2Service<T, S, B>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
@ -66,7 +71,7 @@ impl<S, B> H2Service<TcpStream, S, B>
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
@ -103,7 +108,7 @@ mod openssl {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
@ -147,7 +152,7 @@ mod rustls {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
@ -187,7 +192,7 @@ where
T: AsyncRead + AsyncWrite + Unpin + 'static,
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
@ -225,7 +230,7 @@ where
impl<T, S, B> H2ServiceHandler<T, S, B>
where
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
@ -248,7 +253,7 @@ impl<T, S, B> Service<(T, Option<net::SocketAddr>)> for H2ServiceHandler<T, S, B
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
@ -258,10 +263,10 @@ where
type Future = H2ServiceHandlerResponse<T, S, B>;
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.flow.service.poll_ready(cx).map_err(|e| {
let e = e.into();
error!("Service readiness error: {:?}", e);
DispatchError::Service(e)
self.flow.service.poll_ready(cx).map_err(|err| {
let e = Error::from(err.into());
error!("HTTP/2 service readiness error: {:?}", e);
DispatchError::InternalError
})
}
@ -300,7 +305,7 @@ pub struct H2ServiceHandlerResponse<T, S, B>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
@ -312,7 +317,7 @@ impl<T, S, B> Future for H2ServiceHandlerResponse<T, S, B>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody,

View File

@ -34,7 +34,10 @@ pub mod client;
mod config;
#[cfg(feature = "compress")]
pub mod encoding;
pub mod error;
mod extensions;
pub mod h1;
pub mod h2;
pub mod header;
mod helpers;
mod http_message;
@ -44,12 +47,8 @@ mod request;
mod response;
mod response_builder;
mod service;
mod time_parser;
pub mod error;
pub mod h1;
pub mod h2;
pub mod test;
mod time_parser;
pub mod ws;
pub use self::builder::HttpServiceBuilder;

View File

@ -15,10 +15,9 @@ use actix_service::{
};
use bytes::Bytes;
use futures_core::{future::LocalBoxFuture, ready};
use h2::server::{handshake, Handshake};
use pin_project::pin_project;
use crate::body::MessageBody;
use crate::body::{Body, MessageBody};
use crate::builder::HttpServiceBuilder;
use crate::config::{KeepAlive, ServiceConfig};
use crate::error::{DispatchError, Error};
@ -39,7 +38,7 @@ pub struct HttpService<T, S, B, X = h1::ExpectHandler, U = h1::UpgradeHandler> {
impl<T, S, B> HttpService<T, S, B>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -54,7 +53,7 @@ where
impl<T, S, B> HttpService<T, S, B>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -93,7 +92,7 @@ where
impl<T, S, B, X, U> HttpService<T, S, B, X, U>
where
S: ServiceFactory<Request, Config = ()>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -107,7 +106,7 @@ where
pub fn expect<X1>(self, expect: X1) -> HttpService<T, S, B, X1, U>
where
X1: ServiceFactory<Request, Config = (), Response = Request>,
X1::Error: Into<Error>,
X1::Error: Into<Response<Body>>,
X1::InitError: fmt::Debug,
{
HttpService {
@ -151,7 +150,7 @@ impl<S, B, X, U> HttpService<TcpStream, S, B, X, U>
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -160,7 +159,7 @@ where
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<
@ -169,7 +168,7 @@ where
Response = (),
>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create simple tcp stream service
@ -202,7 +201,7 @@ mod openssl {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -211,7 +210,7 @@ mod openssl {
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<
@ -220,7 +219,7 @@ mod openssl {
Response = (),
>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create openssl based service
@ -269,7 +268,7 @@ mod rustls {
where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -278,7 +277,7 @@ mod rustls {
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<
@ -287,7 +286,7 @@ mod rustls {
Response = (),
>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
/// Create rustls based service
@ -333,7 +332,7 @@ where
S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
@ -342,12 +341,12 @@ where
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
X::InitError: fmt::Debug,
U: ServiceFactory<(Request, Framed<T, h1::Codec>), Config = (), Response = ()>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
U::InitError: fmt::Debug,
{
type Response = ();
@ -410,11 +409,11 @@ where
impl<T, S, B, X, U> HttpServiceHandler<T, S, B, X, U>
where
S: Service<Request>,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
X: Service<Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, h1::Codec>)>,
U::Error: Into<Error>,
U::Error: Into<Response<Body>>,
{
pub(super) fn new(
cfg: ServiceConfig,
@ -432,9 +431,9 @@ where
}
pub(super) fn _poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
ready!(self.flow.expect.poll_ready(cx).map_err(Into::into))?;
ready!(self.flow.expect.poll_ready(cx)).map_err(Into::into)?;
ready!(self.flow.service.poll_ready(cx).map_err(Into::into))?;
ready!(self.flow.service.poll_ready(cx)).map_err(Into::into)?;
if let Some(ref upg) = self.flow.upgrade {
ready!(upg.poll_ready(cx).map_err(Into::into))?;
@ -466,14 +465,14 @@ impl<T, S, B, X, U> Service<(T, Protocol, Option<net::SocketAddr>)>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, h1::Codec>), Response = ()>,
U::Error: fmt::Display + Into<Error>,
U::Error: fmt::Display + Into<Response<Body>>,
{
type Response = ();
type Error = DispatchError;
@ -496,7 +495,7 @@ where
match proto {
Protocol::Http2 => HttpServiceHandlerResponse {
state: State::H2Handshake(Some((
handshake(io),
h2::server::handshake(io),
self.cfg.clone(),
self.flow.clone(),
on_connect_data,
@ -524,11 +523,11 @@ enum State<T, S, B, X, U>
where
S: Service<Request>,
S::Future: 'static,
S::Error: Into<Error>,
S::Error: Into<Response<Body>>,
T: AsyncRead + AsyncWrite + Unpin,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, h1::Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -536,7 +535,7 @@ where
H2(#[pin] Dispatcher<T, S, B, X, U>),
H2Handshake(
Option<(
Handshake<T, Bytes>,
h2::server::Handshake<T, Bytes>,
ServiceConfig,
Rc<HttpFlow<S, X, U>>,
OnConnectData,
@ -550,12 +549,12 @@ pub struct HttpServiceHandlerResponse<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, h1::Codec>), Response = ()>,
U::Error: fmt::Display,
{
@ -567,12 +566,12 @@ impl<T, S, B, X, U> Future for HttpServiceHandlerResponse<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error> + 'static,
S::Error: Into<Response<Body>> + 'static,
S::Future: 'static,
S::Response: Into<Response<B>> + 'static,
B: MessageBody,
X: Service<Request, Response = Request>,
X::Error: Into<Error>,
X::Error: Into<Response<Body>>,
U: Service<(Request, Framed<T, h1::Codec>), Response = ()>,
U::Error: fmt::Display,
{

View File

@ -328,6 +328,7 @@ impl HttpResponseBuilder {
.expect("cannot reuse response builder")
.set_body(body);
// allow unused mut when cookies feature is disabled
#[allow(unused_mut)]
let mut res = HttpResponse::from(res);