mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
This reverts commit 580062228b
.
This commit is contained in:
parent
c3fd27c225
commit
8e5f28839c
13 changed files with 123 additions and 161 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
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};
|
||||
|
@ -20,7 +19,7 @@ use servo_url::{Host, ServoUrl};
|
|||
pub struct HstsEntry {
|
||||
pub host: String,
|
||||
pub include_subdomains: bool,
|
||||
pub max_age: Option<Duration>,
|
||||
pub max_age: Option<u64>,
|
||||
pub timestamp: Option<u64>,
|
||||
}
|
||||
|
||||
|
@ -28,7 +27,7 @@ impl HstsEntry {
|
|||
pub fn new(
|
||||
host: String,
|
||||
subdomains: IncludeSubdomains,
|
||||
max_age: Option<Duration>,
|
||||
max_age: Option<u64>,
|
||||
) -> Option<HstsEntry> {
|
||||
if host.parse::<Ipv4Addr>().is_ok() || host.parse::<Ipv6Addr>().is_ok() {
|
||||
None
|
||||
|
@ -37,12 +36,7 @@ impl HstsEntry {
|
|||
host: host,
|
||||
include_subdomains: (subdomains == IncludeSubdomains::Included),
|
||||
max_age: max_age,
|
||||
timestamp: Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
),
|
||||
timestamp: Some(time::get_time().sec as u64),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -50,11 +44,7 @@ impl HstsEntry {
|
|||
pub fn is_expired(&self) -> bool {
|
||||
match (self.max_age, self.timestamp) {
|
||||
(Some(max_age), Some(timestamp)) => {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default() -
|
||||
Duration::from_secs(timestamp) >=
|
||||
max_age
|
||||
(time::get_time().sec as u64) - timestamp >= max_age
|
||||
},
|
||||
|
||||
_ => false,
|
||||
|
@ -206,9 +196,11 @@ impl HstsList {
|
|||
IncludeSubdomains::NotIncluded
|
||||
};
|
||||
|
||||
if let Some(entry) =
|
||||
HstsEntry::new(host.to_owned(), include_subdomains, Some(header.max_age()))
|
||||
{
|
||||
if let Some(entry) = HstsEntry::new(
|
||||
host.to_owned(),
|
||||
include_subdomains,
|
||||
Some(header.max_age().as_secs()),
|
||||
) {
|
||||
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