Skip to content

Commit

Permalink
Merge pull request #192 from inrustwetrust/flush-errors
Browse files Browse the repository at this point in the history
Filter out the same socket-closing errors on flush as on write
  • Loading branch information
rawler committed Jan 4, 2021
2 parents 4770db9 + 476caa2 commit ffbde0d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/request.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit ffbde0d

Please sign in to comment.