mirror of
https://github.com/actix/actix-web.git
synced 2024-11-27 03:51:10 +00:00
update set_date impl
This commit is contained in:
parent
4fadff63f4
commit
756227896b
3 changed files with 17 additions and 17 deletions
|
@ -101,7 +101,7 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
|||
|
||||
#[inline]
|
||||
fn set_date(&self, dst: &mut BytesMut) {
|
||||
self.settings.set_date(dst)
|
||||
self.settings.set_date(dst, true)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -214,7 +214,7 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
|||
|
||||
// optimized date header, set_date writes \r\n
|
||||
if !has_date {
|
||||
self.settings.set_date(&mut buffer);
|
||||
self.settings.set_date(&mut buffer, true);
|
||||
} else {
|
||||
// msg eof
|
||||
buffer.extend_from_slice(b"\r\n");
|
||||
|
|
|
@ -73,7 +73,7 @@ impl<H: 'static> Writer for H2Writer<H> {
|
|||
|
||||
#[inline]
|
||||
fn set_date(&self, dst: &mut BytesMut) {
|
||||
self.settings.set_date(dst)
|
||||
self.settings.set_date(dst, true)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -97,7 +97,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_simple(&mut bytes);
|
||||
self.settings.set_date(&mut bytes, false);
|
||||
msg.headers_mut()
|
||||
.insert(DATE, HeaderValue::try_from(bytes.freeze()).unwrap());
|
||||
}
|
||||
|
|
|
@ -229,18 +229,18 @@ impl<H> WorkerSettings<H> {
|
|||
unsafe { &mut *self.date.get() }.update();
|
||||
}
|
||||
|
||||
pub fn set_date(&self, dst: &mut BytesMut) {
|
||||
pub fn set_date(&self, dst: &mut BytesMut, full: bool) {
|
||||
if full {
|
||||
let mut buf: [u8; 39] = unsafe { mem::uninitialized() };
|
||||
buf[..6].copy_from_slice(b"date: ");
|
||||
buf[6..35].copy_from_slice(&(unsafe { &*self.date.get() }.bytes));
|
||||
buf[35..].copy_from_slice(b"\r\n\r\n");
|
||||
dst.extend_from_slice(&buf);
|
||||
}
|
||||
|
||||
pub fn set_date_simple(&self, dst: &mut BytesMut) {
|
||||
} else {
|
||||
dst.extend_from_slice(&(unsafe { &*self.date.get() }.bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Date {
|
||||
bytes: [u8; DATE_VALUE_LENGTH],
|
||||
|
@ -284,9 +284,9 @@ mod tests {
|
|||
fn test_date() {
|
||||
let settings = WorkerSettings::<()>::new(Vec::new(), KeepAlive::Os);
|
||||
let mut buf1 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10);
|
||||
settings.set_date(&mut buf1);
|
||||
settings.set_date(&mut buf1, true);
|
||||
let mut buf2 = BytesMut::with_capacity(DATE_VALUE_LENGTH + 10);
|
||||
settings.set_date(&mut buf2);
|
||||
settings.set_date(&mut buf2, true);
|
||||
assert_eq!(buf1, buf2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue