Check for synthetic_error early in unit::connect

This commit is contained in:
Jacob Hoffman-Andrews
2020-10-20 23:46:54 -07:00
committed by Martin Algesten
parent bd2761e280
commit 67c28d28a3
2 changed files with 8 additions and 0 deletions

View File

@@ -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<Error> {
self.error
}
/// The content type part of the "Content-Type" header without
/// the charset.
///

View File

@@ -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