From c63838bb71bfa96c46341982afd17cb3608aaf0b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 9 Oct 2018 13:12:49 -0700 Subject: [PATCH] fix 204 support for http/2 --- CHANGES.md | 7 +++++++ src/server/h2writer.rs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 46f1fb367..260b6df74 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.7.11] - 2018-10-09 + +### Fixed + +* Fixed 204 responses for http/2 + + ## [0.7.10] - 2018-10-09 ### Fixed diff --git a/src/server/h2writer.rs b/src/server/h2writer.rs index 51d4dce6f..66f2923c4 100644 --- a/src/server/h2writer.rs +++ b/src/server/h2writer.rs @@ -96,6 +96,7 @@ impl Writer for H2Writer { let mut has_date = false; let mut resp = Response::new(()); + let mut len_is_set = false; *resp.status_mut() = msg.status(); *resp.version_mut() = Version::HTTP_2; for (key, value) in msg.headers().iter() { @@ -107,6 +108,9 @@ impl Writer for H2Writer { }, CONTENT_LENGTH => match info.length { ResponseLength::None => (), + ResponseLength::Zero => { + len_is_set = true; + } _ => continue, }, DATE => has_date = true, @@ -126,8 +130,10 @@ impl Writer for H2Writer { // content length match info.length { ResponseLength::Zero => { - resp.headers_mut() - .insert(CONTENT_LENGTH, HeaderValue::from_static("0")); + if !len_is_set { + resp.headers_mut() + .insert(CONTENT_LENGTH, HeaderValue::from_static("0")); + } self.flags.insert(Flags::EOF); } ResponseLength::Length(len) => { @@ -144,6 +150,9 @@ impl Writer for H2Writer { resp.headers_mut() .insert(CONTENT_LENGTH, HeaderValue::try_from(l.as_str()).unwrap()); } + ResponseLength::None => { + self.flags.insert(Flags::EOF); + } _ => (), } if let Some(ce) = info.content_encoding {