diff --git a/src/response.rs b/src/response.rs index 38f44f1..a768535 100644 --- a/src/response.rs +++ b/src/response.rs @@ -221,6 +221,11 @@ impl Response { &self.error } + // Internal-only API, to allow unit::connect to return early on errors. + pub(crate) fn into_error(self) -> Option { + self.error + } + /// The content type part of the "Content-Type" header without /// the charset. /// diff --git a/src/unit.rs b/src/unit.rs index 3ec4794..0431009 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -181,6 +181,9 @@ pub(crate) fn connect( // start reading the response to process cookies and redirects. let mut stream = stream::DeadlineStream::new(stream, unit.deadline); let mut resp = Response::from_read(&mut stream); + if resp.synthetic_error().is_some() { + return Err(resp.into_error().unwrap()); + } // https://tools.ietf.org/html/rfc7230#section-6.3.1 // When an inbound connection is closed prematurely, a client MAY