mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
revert DateServiceInner changes
This commit is contained in:
parent
29098f8397
commit
9c3789cbd0
3 changed files with 27 additions and 18 deletions
|
@ -1,5 +1,12 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.7] - 2019-07-18
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Add support for downcasting response errors #986
|
||||||
|
|
||||||
|
|
||||||
## [0.2.6] - 2019-07-17
|
## [0.2.6] - 2019-07-17
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::cell::Cell;
|
use std::cell::UnsafeCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -162,13 +162,17 @@ impl ServiceConfig {
|
||||||
pub fn set_date(&self, dst: &mut BytesMut) {
|
pub fn set_date(&self, dst: &mut BytesMut) {
|
||||||
let mut buf: [u8; 39] = [0; 39];
|
let mut buf: [u8; 39] = [0; 39];
|
||||||
buf[..6].copy_from_slice(b"date: ");
|
buf[..6].copy_from_slice(b"date: ");
|
||||||
buf[6..35].copy_from_slice(&self.0.timer.date().bytes);
|
self.0
|
||||||
|
.timer
|
||||||
|
.set_date(|date| buf[6..35].copy_from_slice(&date.bytes));
|
||||||
buf[35..].copy_from_slice(b"\r\n\r\n");
|
buf[35..].copy_from_slice(b"\r\n\r\n");
|
||||||
dst.extend_from_slice(&buf);
|
dst.extend_from_slice(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_date_header(&self, dst: &mut BytesMut) {
|
pub(crate) fn set_date_header(&self, dst: &mut BytesMut) {
|
||||||
dst.extend_from_slice(&self.0.timer.date().bytes);
|
self.0
|
||||||
|
.timer
|
||||||
|
.set_date(|date| dst.extend_from_slice(&date.bytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,28 +210,24 @@ impl fmt::Write for Date {
|
||||||
struct DateService(Rc<DateServiceInner>);
|
struct DateService(Rc<DateServiceInner>);
|
||||||
|
|
||||||
struct DateServiceInner {
|
struct DateServiceInner {
|
||||||
current: Cell<Option<(Date, Instant)>>,
|
current: UnsafeCell<Option<(Date, Instant)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DateServiceInner {
|
impl DateServiceInner {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
DateServiceInner {
|
DateServiceInner {
|
||||||
current: Cell::new(None),
|
current: UnsafeCell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self) -> Option<(Date, Instant)> {
|
|
||||||
self.current.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset(&self) {
|
fn reset(&self) {
|
||||||
self.current.set(None);
|
unsafe { (&mut *self.current.get()).take() };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&self) {
|
fn update(&self) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let date = Date::new();
|
let date = Date::new();
|
||||||
self.current.set(Some((date, now)));
|
*(unsafe { &mut *self.current.get() }) = Some((date, now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ impl DateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_date(&self) {
|
fn check_date(&self) {
|
||||||
if self.0.get().is_none() {
|
if unsafe { (&*self.0.current.get()).is_none() } {
|
||||||
self.0.update();
|
self.0.update();
|
||||||
|
|
||||||
// periodic date update
|
// periodic date update
|
||||||
|
@ -253,13 +253,12 @@ impl DateService {
|
||||||
|
|
||||||
fn now(&self) -> Instant {
|
fn now(&self) -> Instant {
|
||||||
self.check_date();
|
self.check_date();
|
||||||
self.0.get().unwrap().1
|
unsafe { (&*self.0.current.get()).as_ref().unwrap().1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn date(&self) -> Date {
|
fn set_date<F: FnMut(&Date)>(&self, mut f: F) {
|
||||||
self.check_date();
|
self.check_date();
|
||||||
|
f(&unsafe { (&*self.0.current.get()).as_ref().unwrap().0 })
|
||||||
self.0.get().unwrap().0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
//! Error and Result module
|
//! Error and Result module
|
||||||
|
use std::any::TypeId;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
use std::{fmt, io, result};
|
use std::{fmt, io, result};
|
||||||
use std::any::TypeId;
|
|
||||||
|
|
||||||
pub use actix_threadpool::BlockingError;
|
pub use actix_threadpool::BlockingError;
|
||||||
use actix_utils::timeout::TimeoutError;
|
use actix_utils::timeout::TimeoutError;
|
||||||
|
@ -81,7 +81,10 @@ pub trait ResponseError: fmt::Debug + fmt::Display {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn __private_get_type_id__(&self) -> TypeId where Self: 'static {
|
fn __private_get_type_id__(&self) -> TypeId
|
||||||
|
where
|
||||||
|
Self: 'static,
|
||||||
|
{
|
||||||
TypeId::of::<Self>()
|
TypeId::of::<Self>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue