diff --git a/src/client/connector.rs b/src/client/connector.rs index 3f4916afa..88d6dfd6b 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -285,12 +285,9 @@ impl Default for ClientConnector { Arc::new(config) } + #[cfg_attr(rustfmt, rustfmt_skip)] #[cfg(not(any( - feature = "alpn", - feature = "ssl", - feature = "tls", - feature = "rust-tls", - )))] + feature = "alpn", feature = "ssl", feature = "tls", feature = "rust-tls")))] { () } diff --git a/src/server/error.rs b/src/server/error.rs index b8b602266..4396e6a2a 100644 --- a/src/server/error.rs +++ b/src/server/error.rs @@ -24,8 +24,8 @@ pub enum AcceptorError { /// A set of errors that can occur during dispatching http requests pub enum HttpDispatchError { /// Application error - #[fail(display = "Application specific error")] - AppError, + #[fail(display = "Application specific error: {}", _0)] + App(Error), /// An `io::Error` that occurred while trying to read or write to a network /// stream. @@ -39,6 +39,16 @@ pub enum HttpDispatchError { /// HTTP2 error #[fail(display = "HTTP2 error: {}", _0)] Http2(http2::Error), + + /// Unknown error + #[fail(display = "Unknown error")] + Unknown, +} + +impl From for HttpDispatchError { + fn from(err: Error) -> Self { + HttpDispatchError::App(err) + } } impl From for HttpDispatchError { diff --git a/src/server/h1.rs b/src/server/h1.rs index b17981225..a1a6c0af4 100644 --- a/src/server/h1.rs +++ b/src/server/h1.rs @@ -49,6 +49,7 @@ pub(crate) struct Http1 { payload: Option, buf: BytesMut, tasks: VecDeque>, + error: Option, ka_enabled: bool, ka_expire: Instant, ka_timer: Option, @@ -113,6 +114,7 @@ where decoder: H1Decoder::new(), payload: None, tasks: VecDeque::new(), + error: None, addr, buf, settings, @@ -321,7 +323,11 @@ where return Ok(Async::NotReady); } self.flags.insert(Flags::ERROR); - return Err(HttpDispatchError::AppError); + return Err(self + .error + .take() + .map(|e| e.into()) + .unwrap_or(HttpDispatchError::Unknown)); } match self.tasks[idx].pipe.poll_io(&mut self.stream) { @@ -357,12 +363,13 @@ where io = true; } Err(err) => { + error!("Unhandled error1: {}", err); // it is not possible to recover from error // during pipe handling, so just drop connection self.read_disconnected(); self.write_disconnected(); self.tasks[idx].flags.insert(EntryFlags::ERROR); - error!("Unhandled error1: {}", err); + self.error = Some(err); continue; } } @@ -373,10 +380,11 @@ where self.tasks[idx].flags.insert(EntryFlags::FINISHED) } Err(err) => { + error!("Unhandled error: {}", err); self.read_disconnected(); self.write_disconnected(); self.tasks[idx].flags.insert(EntryFlags::ERROR); - error!("Unhandled error: {}", err); + self.error = Some(err); continue; } } diff --git a/src/server/settings.rs b/src/server/settings.rs index fbe515f99..fe9cd82a3 100644 --- a/src/server/settings.rs +++ b/src/server/settings.rs @@ -145,6 +145,7 @@ impl Clone for WorkerSettings { } impl WorkerSettings { + /// Create instance of `WorkerSettings` pub fn new( handler: H, keep_alive: KeepAlive, client_timeout: u64, settings: ServerSettings, ) -> WorkerSettings {