feat(server): change http1_half_close option default to disabled

Detecting a read hangup is a useful way to determine that a connection
has closed. It's also possible that a client shuts down its read half
without closing the connection, but this is rarer. Thus, by default,
hyper will now assume a read EOF means the connection has closed.

BREAKING CHANGE: The server's behavior will now by default close
  connections when receiving a read EOF. To allow for clients to close
  the read half, call `http1_half_close(true)` when configuring a
  server.
This commit is contained in:
Sean McArthur
2019-10-18 13:08:06 -07:00
parent 8e7ebd80cd
commit 7e31fd88a8
5 changed files with 67 additions and 45 deletions

View File

@@ -60,7 +60,10 @@ where
}
pub fn disable_keep_alive(&mut self) {
self.conn.disable_keep_alive()
self.conn.disable_keep_alive();
if self.conn.is_write_closed() {
self.close();
}
}
pub fn into_inner(self) -> (I, Bytes, D) {
@@ -233,10 +236,17 @@ where
// if here, the dispatcher gave the user the error
// somewhere else. we still need to shutdown, but
// not as a second error.
self.close();
Poll::Ready(Ok(()))
},
None => {
// read eof, conn will start to shutdown automatically
// read eof, the write side will have been closed too unless
// allow_read_close was set to true, in which case just do
// nothing...
debug_assert!(self.conn.is_read_closed());
if self.conn.is_write_closed() {
self.close();
}
Poll::Ready(Ok(()))
}
}