Replace time with std::time in components/net (#31079)

* Replace time with std::time in components/net

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

* Fix cookie::test_sort_order test

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>

---------

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-01-17 15:18:20 +01:00 committed by GitHub
parent d86e713a9c
commit 580062228b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 161 additions and 123 deletions

View file

@ -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