From 87c01815823eeda2a34d727c149b949c6a1689cd Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 18 May 2021 15:06:36 +0100 Subject: [PATCH] use into stderror bounds in dispatchers for body errors --- actix-http/src/builder.rs | 8 +++----- actix-http/src/error.rs | 5 +++++ actix-http/src/h1/dispatcher.rs | 19 ++++++++++--------- actix-http/src/h1/service.rs | 26 ++++++++++++++------------ actix-http/src/h2/dispatcher.rs | 18 +++++++++++++----- actix-http/src/h2/service.rs | 28 ++++++++++++++++------------ actix-http/src/service.rs | 19 ++++++++++--------- actix-test/src/lib.rs | 7 +++---- src/server.rs | 9 +++++---- 9 files changed, 79 insertions(+), 60 deletions(-) diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index 58c369066..4e68dc920 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -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> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { let cfg = ServiceConfig::new( self.keep_alive, @@ -230,7 +228,7 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { let cfg = ServiceConfig::new( self.keep_alive, diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index b9b58b7d9..19a10ddc1 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -370,6 +370,11 @@ pub enum DispatchError { #[display(fmt = "Service Error")] Service(#[error(not(source))] Response), + /// Body error + // FIXME: display and error type + #[display(fmt = "Body Error")] + Body(#[error(not(source))] Box), + /// Upgrade service error Upgrade, diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 7f1af7840..b4adde638 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -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>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -75,7 +76,7 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -94,7 +95,7 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -136,7 +137,7 @@ where X: Service, B: MessageBody, - B::Error: Into>, + B::Error: Into>, { None, ExpectCall(#[pin] X::Future), @@ -152,7 +153,7 @@ where X: Service, B: MessageBody, - B::Error: Into>, + B::Error: Into>, { fn is_empty(&self) -> bool { matches!(self, State::None) @@ -174,7 +175,7 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -235,7 +236,7 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -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>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index 2b7a001b7..dbad8cfac 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -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 { @@ -66,7 +68,7 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -115,7 +117,7 @@ mod openssl { S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -175,7 +177,7 @@ mod rustls { S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -273,7 +275,7 @@ where S::InitError: fmt::Debug, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -342,7 +344,7 @@ where S::Response: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 346862055..7f0766f13 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -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> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { type Output = Result<(), DispatchError>; @@ -144,7 +152,7 @@ where I: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, { fn prepare_response( &self, @@ -222,7 +230,7 @@ where I: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, { type Output = (); diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index ab585410c..ebced7856 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -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 >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { /// Create new `H2Service` instance with config. pub(crate) fn with_config>( @@ -73,7 +77,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { /// Create plain TCP based service pub fn tcp( @@ -112,7 +116,7 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { /// Create OpenSSL based service pub fn openssl( @@ -158,7 +162,7 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { /// Create Rustls based service pub fn rustls( @@ -201,7 +205,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { type Response = (); type Error = DispatchError; @@ -263,7 +267,7 @@ where S::Future: 'static, S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { type Response = (); type Error = DispatchError; @@ -328,7 +332,7 @@ where S::Future: 'static, S::Response: Into> + 'static, B: MessageBody, - B::Error: Into>, + B::Error: Into>, { type Output = Result<(), DispatchError>; diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index b01f27156..b07803af1 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -1,4 +1,5 @@ use std::{ + error::Error as StdError, fmt, future::Future, marker::PhantomData, @@ -59,7 +60,7 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { /// Create new `HttpService` instance. pub fn new>(service: F) -> Self { @@ -158,7 +159,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -210,7 +211,7 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -278,7 +279,7 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -343,7 +344,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: ServiceFactory, X::Future: 'static, @@ -480,7 +481,7 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -542,7 +543,7 @@ where S::Error: Into>, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -574,7 +575,7 @@ where S::Response: Into> + 'static, B: MessageBody, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, @@ -596,7 +597,7 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, X: Service, X::Error: Into>, diff --git a/actix-test/src/lib.rs b/actix-test/src/lib.rs index 495964ba0..a788b0f6d 100644 --- a/actix-test/src/lib.rs +++ b/actix-test/src/lib.rs @@ -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> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { start_with(TestServerConfig::default(), factory) } @@ -127,7 +126,7 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, - B::Error: Into>, + B::Error: Into>, { let (tx, rx) = mpsc::channel(); diff --git a/src/server.rs b/src/server.rs index 3616db3c4..9ee304d84 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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>, + B::Error: Into>, { /// Create new HTTP server with application factory pub fn new(factory: F) -> Self {