mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
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:
parent
d86e713a9c
commit
580062228b
13 changed files with 161 additions and 123 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use embedder_traits::resources::{self, Resource};
|
||||
use headers::{HeaderMapExt, StrictTransportSecurity};
|
||||
|
@ -19,7 +20,7 @@ use servo_url::{Host, ServoUrl};
|
|||
pub struct HstsEntry {
|
||||
pub host: String,
|
||||
pub include_subdomains: bool,
|
||||
pub max_age: Option<u64>,
|
||||
pub max_age: Option<Duration>,
|
||||
pub timestamp: Option<u64>,
|
||||
}
|
||||
|
||||
|
@ -27,7 +28,7 @@ impl HstsEntry {
|
|||
pub fn new(
|
||||
host: String,
|
||||
subdomains: IncludeSubdomains,
|
||||
max_age: Option<u64>,
|
||||
max_age: Option<Duration>,
|
||||
) -> Option<HstsEntry> {
|
||||
if host.parse::<Ipv4Addr>().is_ok() || host.parse::<Ipv6Addr>().is_ok() {
|
||||
None
|
||||
|
@ -36,7 +37,12 @@ impl HstsEntry {
|
|||
host: host,
|
||||
include_subdomains: (subdomains == IncludeSubdomains::Included),
|
||||
max_age: max_age,
|
||||
timestamp: Some(time::get_time().sec as u64),
|
||||
timestamp: Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +50,11 @@ impl HstsEntry {
|
|||
pub fn is_expired(&self) -> bool {
|
||||
match (self.max_age, self.timestamp) {
|
||||
(Some(max_age), Some(timestamp)) => {
|
||||
(time::get_time().sec as u64) - timestamp >= max_age
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default() -
|
||||
Duration::from_secs(timestamp) >=
|
||||
max_age
|
||||
},
|
||||
|
||||
_ => false,
|
||||
|
@ -196,11 +206,9 @@ impl HstsList {
|
|||
IncludeSubdomains::NotIncluded
|
||||
};
|
||||
|
||||
if let Some(entry) = HstsEntry::new(
|
||||
host.to_owned(),
|
||||
include_subdomains,
|
||||
Some(header.max_age().as_secs()),
|
||||
) {
|
||||
if let Some(entry) =
|
||||
HstsEntry::new(host.to_owned(), include_subdomains, Some(header.max_age()))
|
||||
{
|
||||
info!("adding host {} to the strict transport security list", host);
|
||||
info!("- max-age {}", header.max_age().as_secs());
|
||||
if header.include_subdomains() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue