From 67c28d28a352c832b7357e0eb0a015cc3c3d2155 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Tue, 20 Oct 2020 23:46:54 -0700 Subject: [PATCH] Check for synthetic_error early in unit::connect --- src/response.rs | 5 +++++ src/unit.rs | 3 +++ 2 files changed, 8 insertions(+) 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