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

@ -9,11 +9,12 @@
//! This library will eventually become the core of the Fetch crate
//! with CORSRequest being expanded into FetchRequest (etc)
use std::time::{Duration, SystemTime};
use http::header::HeaderName;
use http::Method;
use net_traits::request::{CredentialsMode, Origin, Request};
use servo_url::ServoUrl;
use time::{self, Timespec};
/// Union type for CORS cache entries
///
@ -45,17 +46,17 @@ impl HeaderOrMethod {
pub struct CorsCacheEntry {
pub origin: Origin,
pub url: ServoUrl,
pub max_age: u32,
pub max_age: Duration,
pub credentials: bool,
pub header_or_method: HeaderOrMethod,
created: Timespec,
created: SystemTime,
}
impl CorsCacheEntry {
fn new(
origin: Origin,
url: ServoUrl,
max_age: u32,
max_age: Duration,
credentials: bool,
header_or_method: HeaderOrMethod,
) -> CorsCacheEntry {
@ -65,7 +66,7 @@ impl CorsCacheEntry {
max_age: max_age,
credentials: credentials,
header_or_method: header_or_method,
created: time::now().to_timespec(),
created: SystemTime::now(),
}
}
}
@ -111,10 +112,11 @@ impl CorsCache {
/// Remove old entries
pub fn cleanup(&mut self) {
let CorsCache(buf) = self.clone();
let now = time::now().to_timespec();
let now = SystemTime::now();
let new_buf: Vec<CorsCacheEntry> = buf
.into_iter()
.filter(|e| now.sec < e.created.sec + e.max_age as i64)
.filter(|e| now < e.created + e.max_age)
.collect();
*self = CorsCache(new_buf);
}
@ -133,7 +135,7 @@ impl CorsCache {
&mut self,
request: &Request,
header_name: &HeaderName,
new_max_age: u32,
new_max_age: Duration,
) -> bool {
match self
.find_entry_by_header(&request, header_name)
@ -167,7 +169,7 @@ impl CorsCache {
&mut self,
request: &Request,
method: Method,
new_max_age: u32,
new_max_age: Duration,
) -> bool {
match self
.find_entry_by_method(&request, method.clone())