fix(http2): add Date header if not present for HTTP2 server responses

This commit is contained in:
Sean McArthur
2018-10-08 17:52:08 -07:00
parent 3e12bccac0
commit 37ec724fd6
5 changed files with 149 additions and 36 deletions

View File

@@ -193,6 +193,15 @@ where
let (head, body) = res.into_parts();
let mut res = ::http::Response::from_parts(head, ());
super::strip_connection_headers(res.headers_mut(), false);
// set Date header if it isn't already set...
res
.headers_mut()
.entry(::http::header::DATE)
.expect("DATE is a valid HeaderName")
.or_insert_with(::proto::h1::date::update_and_header_value);
// automatically set Content-Length from body...
if let Some(len) = body.content_length() {
headers::set_content_length_if_missing(res.headers_mut(), len);
}