From d9496d46d17d21a762df4286cc1b388040a3fe8f Mon Sep 17 00:00:00 2001 From: Zeyi Fan Date: Thu, 28 Mar 2019 17:40:12 -0700 Subject: [PATCH] [0.7] Fix never-ending HTTP2 empty response (#737) * Fix never-ending HTTP2 empty response #737 --- CHANGES.md | 2 ++ src/server/h2writer.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 57333613..e78ef4fc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,8 @@ * Fix preflight CORS header compliance; refactor previous patch (#603). #717 +* Fix never-ending HTTP2 request when response is empty (#709). #737 + ## [0.7.18] - 2019-01-10 ### Added diff --git a/src/server/h2writer.rs b/src/server/h2writer.rs index fef6f889..0dff794e 100644 --- a/src/server/h2writer.rs +++ b/src/server/h2writer.rs @@ -234,6 +234,16 @@ impl Writer for H2Writer { stream.reserve_capacity(cmp::min(self.buffer.len(), CHUNK_SIZE)); } + if self.flags.contains(Flags::EOF) + && !self.flags.contains(Flags::RESERVED) + && self.buffer.is_empty() + { + if let Err(e) = stream.send_data(Bytes::new(), true) { + return Err(io::Error::new(io::ErrorKind::Other, e)); + } + return Ok(Async::Ready(())); + } + loop { match stream.poll_capacity() { Ok(Async::NotReady) => return Ok(Async::NotReady),