mirror of
https://github.com/servo/servo.git
synced 2025-06-13 10:54:29 +00:00
This reverts commit 580062228b
.
This commit is contained in:
parent
c3fd27c225
commit
8e5f28839c
13 changed files with 123 additions and 161 deletions
|
@ -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: SystemTime,
|
||||
pub creation_time: Tm,
|
||||
#[serde(
|
||||
deserialize_with = "hyper_serde::deserialize",
|
||||
serialize_with = "hyper_serde::serialize"
|
||||
)]
|
||||
pub last_access: SystemTime,
|
||||
pub expiry_time: Option<Serde<SystemTime>>,
|
||||
pub last_access: Tm,
|
||||
pub expiry_time: Option<Serde<Tm>>,
|
||||
}
|
||||
|
||||
impl Cookie {
|
||||
|
@ -62,16 +62,11 @@ impl Cookie {
|
|||
let (persistent, expiry_time) = match (cookie.max_age(), cookie.expires()) {
|
||||
(Some(max_age), _) => (
|
||||
true,
|
||||
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(at(
|
||||
now().to_timespec() + Duration::seconds(max_age.num_seconds())
|
||||
)),
|
||||
),
|
||||
(_, Some(expires)) => (true, Some(expires)),
|
||||
_ => (false, None),
|
||||
};
|
||||
|
||||
|
@ -140,18 +135,18 @@ impl Cookie {
|
|||
cookie,
|
||||
host_only,
|
||||
persistent,
|
||||
creation_time: SystemTime::now(),
|
||||
last_access: SystemTime::now(),
|
||||
creation_time: now(),
|
||||
last_access: now(),
|
||||
expiry_time: expiry_time.map(Serde),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn touch(&mut self) {
|
||||
self.last_access = SystemTime::now();
|
||||
self.last_access = now();
|
||||
}
|
||||
|
||||
pub fn set_expiry_time_negative(&mut self) {
|
||||
self.expiry_time = Some(Serde(SystemTime::now() - Duration::from_secs(1)));
|
||||
self.expiry_time = Some(Serde(now() - Duration::seconds(1)));
|
||||
}
|
||||
|
||||
// http://tools.ietf.org/html/rfc6265#section-5.1.4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue