Skip to content

Commit 476caa2

Browse files
author
John Talling
committed
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.
1 parent 4770db9 commit 476caa2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Diff for: src/request.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -435,22 +435,25 @@ impl Request {
435435

436436
let do_not_send_body = self.method == Method::Head;
437437

438-
match response.raw_print(
438+
Self::ignore_client_closing_errors(response.raw_print(
439439
writer.by_ref(),
440440
self.http_version.clone(),
441441
&self.headers,
442442
do_not_send_body,
443443
None,
444-
) {
445-
Ok(_) => (),
446-
Err(ref err) if err.kind() == ErrorKind::BrokenPipe => (),
447-
Err(ref err) if err.kind() == ErrorKind::ConnectionAborted => (),
448-
Err(ref err) if err.kind() == ErrorKind::ConnectionRefused => (),
449-
Err(ref err) if err.kind() == ErrorKind::ConnectionReset => (),
450-
Err(err) => return Err(err),
451-
};
452-
453-
writer.flush()
444+
))?;
445+
446+
Self::ignore_client_closing_errors(writer.flush())
447+
}
448+
449+
fn ignore_client_closing_errors(result: io::Result<()>) -> io::Result<()> {
450+
result.or_else(|err| match err.kind() {
451+
ErrorKind::BrokenPipe => Ok(()),
452+
ErrorKind::ConnectionAborted => Ok(()),
453+
ErrorKind::ConnectionRefused => Ok(()),
454+
ErrorKind::ConnectionReset => Ok(()),
455+
_ => Err(err),
456+
})
454457
}
455458

456459
pub(crate) fn with_notify_sender(mut self, sender: Sender<()>) -> Self {

0 commit comments

Comments
 (0)