Skip to content

Commit

Permalink
Fix http/2 date header generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Mar 20, 2018
1 parent 978091c commit c4f4cad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

* Allow to set client websocket handshake timeout

* Refactor `TestServer` configuration

* Fix server websockets big payloads support

* Refactor `TestServer` configuration
* Fix http/2 date header generation


## 0.4.9 (2018-03-16)
Expand Down
2 changes: 1 addition & 1 deletion src/server/h2writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<H: 'static> Writer for H2Writer<H> {
// using helpers::date is quite a lot faster
if !msg.headers().contains_key(DATE) {
let mut bytes = BytesMut::with_capacity(29);
self.settings.set_date(&mut bytes);
self.settings.set_date_simple(&mut bytes);
msg.headers_mut().insert(DATE, HeaderValue::try_from(bytes.freeze()).unwrap());
}

Expand Down
4 changes: 4 additions & 0 deletions src/server/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ impl<H> WorkerSettings<H> {
buf[35..].copy_from_slice(b"\r\n\r\n");
dst.extend_from_slice(&buf);
}

pub fn set_date_simple(&self, dst: &mut BytesMut) {
dst.extend_from_slice(&(unsafe{&*self.date.get()}.bytes));
}
}

struct Date {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ fn test_h2() {
})
})
});
let _res = core.run(tcp);
// assert_eq!(res.unwrap(), Bytes::from_static(STR.as_ref()));
let res = core.run(tcp);
assert_eq!(res.unwrap(), Bytes::from_static(STR.as_ref()));
}

#[test]
Expand Down

0 comments on commit c4f4cad

Please sign in to comment.