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

View File

@ -370,6 +370,11 @@ pub enum DispatchError {
#[display(fmt = "Service Error")]
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,

View File

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

View File

@ -1,7 +1,11 @@
use std::marker::PhantomData;
use std::rc::Rc;
use std::task::{Context, Poll};
use std::{fmt, net};
use std::{
error::Error as StdError,
fmt,
marker::PhantomData,
net,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_rt::net::TcpStream;
@ -19,9 +23,7 @@ use crate::{
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> {
@ -66,7 +68,7 @@ where
S::Response: Into<Response<B>>,
B: MessageBody,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
@ -115,7 +117,7 @@ mod openssl {
S::Response: Into<Response<B>>,
B: MessageBody,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
@ -175,7 +177,7 @@ mod rustls {
S::Response: Into<Response<B>>,
B: MessageBody,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
@ -273,7 +275,7 @@ where
S::InitError: fmt::Debug,
B: MessageBody,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
@ -342,7 +344,7 @@ where
S::Response: Into<Response<B>>,
B: MessageBody,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
X: Service<Request, Response = Request>,
X::Error: Into<Response<AnyBody>>,

View File

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

View File

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

View File

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

View File

@ -31,12 +31,11 @@ extern crate tls_openssl as openssl;
#[cfg(feature = "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};
pub use actix_http::test::TestBuffer;
use actix_http::{
body::AnyBody,
http::{HeaderMap, Method},
ws, HttpService, Request, Response,
};
@ -87,7 +86,7 @@ where
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
{
start_with(TestServerConfig::default(), factory)
}
@ -127,7 +126,7 @@ where
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static,
B::Error: Into<Response<AnyBody>>,
B::Error: Into<Box<dyn StdError>>,
{
let (tx, rx) = mpsc::channel();

View File

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