use into stderror bounds in dispatchers for body errors

This commit is contained in:
Rob Ede 2021-05-18 15:06:36 +01:00
parent ea6f0cd49a
commit 87c0181582
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
9 changed files with 79 additions and 60 deletions

View File

@ -1,6 +1,4 @@
use std::marker::PhantomData; use std::{error::Error as StdError, fmt, marker::PhantomData, net, rc::Rc};
use std::rc::Rc;
use std::{fmt, net};
use actix_codec::Framed; use actix_codec::Framed;
use actix_service::{IntoServiceFactory, Service, ServiceFactory}; use actix_service::{IntoServiceFactory, Service, ServiceFactory};
@ -207,7 +205,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
let cfg = ServiceConfig::new( let cfg = ServiceConfig::new(
self.keep_alive, self.keep_alive,
@ -230,7 +228,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
let cfg = ServiceConfig::new( let cfg = ServiceConfig::new(
self.keep_alive, self.keep_alive,

View File

@ -370,6 +370,11 @@ pub enum DispatchError {
#[display(fmt = "Service Error")] #[display(fmt = "Service Error")]
Service(#[error(not(source))] Response<AnyBody>), Service(#[error(not(source))] Response<AnyBody>),
/// Body error
// FIXME: display and error type
#[display(fmt = "Body Error")]
Body(#[error(not(source))] Box<dyn StdError>),
/// Upgrade service error /// Upgrade service error
Upgrade, Upgrade,

View File

@ -1,5 +1,6 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
error::Error as StdError,
fmt, fmt,
future::Future, future::Future,
io, mem, net, io, mem, net,
@ -53,7 +54,7 @@ where
S::Error: Into<Response<AnyBody>>, S::Error: Into<Response<AnyBody>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -75,7 +76,7 @@ where
S::Error: Into<Response<AnyBody>>, S::Error: Into<Response<AnyBody>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -94,7 +95,7 @@ where
S::Error: Into<Response<AnyBody>>, S::Error: Into<Response<AnyBody>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -136,7 +137,7 @@ where
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
None, None,
ExpectCall(#[pin] X::Future), ExpectCall(#[pin] X::Future),
@ -152,7 +153,7 @@ where
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {
matches!(self, State::None) matches!(self, State::None)
@ -174,7 +175,7 @@ where
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -235,7 +236,7 @@ where
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -438,7 +439,7 @@ where
} }
Poll::Ready(Some(Err(err))) => { Poll::Ready(Some(Err(err))) => {
return Err(DispatchError::Service(err.into())) return Err(DispatchError::Body(err.into()))
} }
Poll::Pending => return Ok(PollResponse::DoNothing), Poll::Pending => return Ok(PollResponse::DoNothing),
@ -913,7 +914,7 @@ where
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,

View File

@ -1,7 +1,11 @@
use std::marker::PhantomData; use std::{
use std::rc::Rc; error::Error as StdError,
use std::task::{Context, Poll}; fmt,
use std::{fmt, net}; marker::PhantomData,
net,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_rt::net::TcpStream; use actix_rt::net::TcpStream;
@ -19,9 +23,7 @@ use crate::{
ConnectCallback, OnConnectData, Request, Response, ConnectCallback, OnConnectData, Request, Response,
}; };
use super::codec::Codec; use super::{codec::Codec, dispatcher::Dispatcher, ExpectHandler, UpgradeHandler};
use super::dispatcher::Dispatcher;
use super::{ExpectHandler, UpgradeHandler};
/// `ServiceFactory` implementation for HTTP1 transport /// `ServiceFactory` implementation for HTTP1 transport
pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> { pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> {
@ -66,7 +68,7 @@ where
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -115,7 +117,7 @@ mod openssl {
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -175,7 +177,7 @@ mod rustls {
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -273,7 +275,7 @@ where
S::InitError: fmt::Debug, S::InitError: fmt::Debug,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -342,7 +344,7 @@ where
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,

View File

@ -1,5 +1,13 @@
use std::task::{Context, Poll}; use std::{
use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc}; cmp,
error::Error as StdError,
future::Future,
marker::PhantomData,
net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite}; use actix_codec::{AsyncRead, AsyncWrite};
use actix_service::Service; use actix_service::Service;
@ -74,7 +82,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
type Output = Result<(), DispatchError>; type Output = Result<(), DispatchError>;
@ -144,7 +152,7 @@ where
I: Into<Response<B>>, I: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
fn prepare_response( fn prepare_response(
&self, &self,
@ -222,7 +230,7 @@ where
I: Into<Response<B>>, I: Into<Response<B>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
type Output = (); type Output = ();

View File

@ -1,8 +1,12 @@
use std::future::Future; use std::{
use std::marker::PhantomData; error::Error as StdError,
use std::pin::Pin; future::Future,
use std::task::{Context, Poll}; marker::PhantomData,
use std::{net, rc::Rc}; net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite}; use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::net::TcpStream; use actix_rt::net::TcpStream;
@ -42,7 +46,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create new `H2Service` instance with config. /// Create new `H2Service` instance with config.
pub(crate) fn with_config<F: IntoServiceFactory<S, Request>>( pub(crate) fn with_config<F: IntoServiceFactory<S, Request>>(
@ -73,7 +77,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create plain TCP based service /// Create plain TCP based service
pub fn tcp( pub fn tcp(
@ -112,7 +116,7 @@ mod openssl {
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create OpenSSL based service /// Create OpenSSL based service
pub fn openssl( pub fn openssl(
@ -158,7 +162,7 @@ mod rustls {
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create Rustls based service /// Create Rustls based service
pub fn rustls( pub fn rustls(
@ -201,7 +205,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
type Response = (); type Response = ();
type Error = DispatchError; type Error = DispatchError;
@ -263,7 +267,7 @@ where
S::Future: 'static, S::Future: 'static,
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
type Response = (); type Response = ();
type Error = DispatchError; type Error = DispatchError;
@ -328,7 +332,7 @@ where
S::Future: 'static, S::Future: 'static,
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
type Output = Result<(), DispatchError>; type Output = Result<(), DispatchError>;

View File

@ -1,4 +1,5 @@
use std::{ use std::{
error::Error as StdError,
fmt, fmt,
future::Future, future::Future,
marker::PhantomData, marker::PhantomData,
@ -59,7 +60,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create new `HttpService` instance. /// Create new `HttpService` instance.
pub fn new<F: IntoServiceFactory<S, Request>>(service: F) -> Self { pub fn new<F: IntoServiceFactory<S, Request>>(service: F) -> Self {
@ -158,7 +159,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -210,7 +211,7 @@ mod openssl {
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -278,7 +279,7 @@ mod rustls {
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -343,7 +344,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>, X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static, X::Future: 'static,
@ -480,7 +481,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -542,7 +543,7 @@ where
S::Error: Into<Response<AnyBody>>, S::Error: Into<Response<AnyBody>>,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -574,7 +575,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody, B: MessageBody,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,
@ -596,7 +597,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>, X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>, X::Error: Into<Response<AnyBody>>,

View File

@ -31,12 +31,11 @@ extern crate tls_openssl as openssl;
#[cfg(feature = "rustls")] #[cfg(feature = "rustls")]
extern crate tls_rustls as rustls; extern crate tls_rustls as rustls;
use std::{fmt, net, sync::mpsc, thread, time}; use std::{error::Error as StdError, fmt, net, sync::mpsc, thread, time};
use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_codec::{AsyncRead, AsyncWrite, Framed};
pub use actix_http::test::TestBuffer; pub use actix_http::test::TestBuffer;
use actix_http::{ use actix_http::{
body::AnyBody,
http::{HeaderMap, Method}, http::{HeaderMap, Method},
ws, HttpService, Request, Response, ws, HttpService, Request, Response,
}; };
@ -87,7 +86,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
start_with(TestServerConfig::default(), factory) start_with(TestServerConfig::default(), factory)
} }
@ -127,7 +126,7 @@ where
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();

View File

@ -1,14 +1,15 @@
use std::{ use std::{
any::Any, any::Any,
cmp, fmt, io, cmp,
error::Error as StdError,
fmt, io,
marker::PhantomData, marker::PhantomData,
net, net,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use actix_http::{ use actix_http::{
body::{AnyBody, MessageBody}, body::MessageBody, Error, Extensions, HttpService, KeepAlive, Request, Response,
Error, Extensions, HttpService, KeepAlive, Request, Response,
}; };
use actix_server::{Server, ServerBuilder}; use actix_server::{Server, ServerBuilder};
use actix_service::{ use actix_service::{
@ -84,7 +85,7 @@ where
S::Service: 'static, S::Service: 'static,
// S::Service: 'static, // S::Service: 'static,
B: MessageBody + 'static, B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>, B::Error: Into<Box<dyn StdError>>,
{ {
/// Create new HTTP server with application factory /// Create new HTTP server with application factory
pub fn new(factory: F) -> Self { pub fn new(factory: F) -> Self {