mirror of
https://github.com/servo/servo.git
synced 2025-07-22 06:43:40 +01:00
Stop using time@0.1
in Servo (#33394)
This removes the last few uses of `time@0.1` in Servo. There are still dependencies from `style` and `webrender`, but they will be removed soon as well. The uses of this version of `time` are replaced with `std::time` types and `time@0.3` when negative `Duration` is necessary. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
095590e224
commit
bc8d8b62c3
18 changed files with 88 additions and 103 deletions
|
@ -4,7 +4,9 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::time::Duration;
|
||||
|
||||
use base::cross_process_instant::CrossProcessInstant;
|
||||
use embedder_traits::resources::{self, Resource};
|
||||
use headers::{HeaderMapExt, StrictTransportSecurity};
|
||||
use http::HeaderMap;
|
||||
|
@ -19,15 +21,15 @@ use servo_url::{Host, ServoUrl};
|
|||
pub struct HstsEntry {
|
||||
pub host: String,
|
||||
pub include_subdomains: bool,
|
||||
pub max_age: Option<u64>,
|
||||
pub timestamp: Option<u64>,
|
||||
pub max_age: Option<Duration>,
|
||||
pub timestamp: Option<CrossProcessInstant>,
|
||||
}
|
||||
|
||||
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,16 +38,14 @@ impl HstsEntry {
|
|||
host,
|
||||
include_subdomains: (subdomains == IncludeSubdomains::Included),
|
||||
max_age,
|
||||
timestamp: Some(time::get_time().sec as u64),
|
||||
timestamp: Some(CrossProcessInstant::now()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
},
|
||||
(Some(max_age), Some(timestamp)) => CrossProcessInstant::now() - timestamp >= max_age,
|
||||
|
||||
_ => false,
|
||||
}
|
||||
|
@ -187,11 +187,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