From 476caa2f727b8f9cdd74e0cc4caa4450a055ed71 Mon Sep 17 00:00:00 2001 From: John Talling Date: Fri, 18 Dec 2020 16:22:29 +0100 Subject: [PATCH] Filter out the same socket-closing errors on flush as on write Before this change, if a broken-pipe or similar error happened in the call to `flush()` instead of `raw_print()`, it would not be suppressed but instead surfaced to the caller. --- src/request.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/request.rs b/src/request.rs index 5485c7a81..74a4744d5 100644 --- a/src/request.rs +++ b/src/request.rs @@ -435,22 +435,25 @@ impl Request { let do_not_send_body = self.method == Method::Head; - match response.raw_print( + Self::ignore_client_closing_errors(response.raw_print( writer.by_ref(), self.http_version.clone(), &self.headers, do_not_send_body, None, - ) { - Ok(_) => (), - Err(ref err) if err.kind() == ErrorKind::BrokenPipe => (), - Err(ref err) if err.kind() == ErrorKind::ConnectionAborted => (), - Err(ref err) if err.kind() == ErrorKind::ConnectionRefused => (), - Err(ref err) if err.kind() == ErrorKind::ConnectionReset => (), - Err(err) => return Err(err), - }; - - writer.flush() + ))?; + + Self::ignore_client_closing_errors(writer.flush()) + } + + fn ignore_client_closing_errors(result: io::Result<()>) -> io::Result<()> { + result.or_else(|err| match err.kind() { + ErrorKind::BrokenPipe => Ok(()), + ErrorKind::ConnectionAborted => Ok(()), + ErrorKind::ConnectionRefused => Ok(()), + ErrorKind::ConnectionReset => Ok(()), + _ => Err(err), + }) } pub(crate) fn with_notify_sender(mut self, sender: Sender<()>) -> Self {