mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
parent
8d39fb6dcf
commit
15c90a58b2
5 changed files with 68 additions and 4 deletions
|
@ -194,7 +194,7 @@ pub struct HSTSEntry {
|
|||
pub host: String,
|
||||
pub include_subdomains: bool,
|
||||
pub max_age: Option<u64>,
|
||||
timestamp: Option<u64>
|
||||
pub timestamp: Option<u64>
|
||||
}
|
||||
|
||||
impl HSTSEntry {
|
||||
|
@ -211,12 +211,22 @@ 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
|
||||
},
|
||||
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn matches_domain(&self, host: &str) -> bool {
|
||||
self.host == host
|
||||
!self.is_expired() && self.host == host
|
||||
}
|
||||
|
||||
fn matches_subdomain(&self, host: &str) -> bool {
|
||||
host.ends_with(&format!(".{}", self.host))
|
||||
!self.is_expired() && host.ends_with(&format!(".{}", self.host))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +264,7 @@ impl HSTSList {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn has_subdomain(&self, host: String) -> bool {
|
||||
fn has_subdomain(&self, host: String) -> bool {
|
||||
self.entries.iter().any(|e| {
|
||||
e.matches_subdomain(&host)
|
||||
})
|
||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -876,6 +876,7 @@ dependencies = [
|
|||
"net 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"url 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue