diff options
Diffstat (limited to 'components/net/cookie.rs')
-rw-r--r-- | components/net/cookie.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/components/net/cookie.rs b/components/net/cookie.rs index d65c98daf18..f00bd897e50 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -7,13 +7,13 @@ use std::borrow::ToOwned; use std::net::{Ipv4Addr, Ipv6Addr}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use hyper_serde::Serde; use net_traits::pub_domains::is_pub_domain; use net_traits::CookieSource; use serde::{Deserialize, Serialize}; use servo_url::ServoUrl; -use time::{at, now, Duration, Tm}; /// A stored cookie that wraps the definition in cookie-rs. This is used to implement /// various behaviours defined in the spec that rely on an associated request URL, @@ -31,13 +31,13 @@ pub struct Cookie { deserialize_with = "hyper_serde::deserialize", serialize_with = "hyper_serde::serialize" )] - pub creation_time: Tm, + pub creation_time: SystemTime, #[serde( deserialize_with = "hyper_serde::deserialize", serialize_with = "hyper_serde::serialize" )] - pub last_access: Tm, - pub expiry_time: Option<Serde<Tm>>, + pub last_access: SystemTime, + pub expiry_time: Option<Serde<SystemTime>>, } impl Cookie { @@ -62,11 +62,16 @@ impl Cookie { let (persistent, expiry_time) = match (cookie.max_age(), cookie.expires()) { (Some(max_age), _) => ( true, - Some(at( - now().to_timespec() + Duration::seconds(max_age.num_seconds()) - )), + Some(SystemTime::now() + Duration::from_secs(max_age.num_seconds() as u64)), + ), + (_, Some(expires)) => ( + true, + Some( + UNIX_EPOCH + + Duration::from_secs(expires.to_timespec().sec as u64) + + Duration::from_nanos(expires.to_timespec().nsec as u64), + ), ), - (_, Some(expires)) => (true, Some(expires)), _ => (false, None), }; @@ -135,18 +140,18 @@ impl Cookie { cookie, host_only, persistent, - creation_time: now(), - last_access: now(), + creation_time: SystemTime::now(), + last_access: SystemTime::now(), expiry_time: expiry_time.map(Serde), }) } pub fn touch(&mut self) { - self.last_access = now(); + self.last_access = SystemTime::now(); } pub fn set_expiry_time_negative(&mut self) { - self.expiry_time = Some(Serde(now() - Duration::seconds(1))); + self.expiry_time = Some(Serde(SystemTime::now() - Duration::from_secs(1))); } // http://tools.ietf.org/html/rfc6265#section-5.1.4 |