mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
make is_origin_trustworthy a method of ServoUrl + fix localhost handling
This commit is contained in:
parent
a7c5c97616
commit
357b486455
4 changed files with 30 additions and 46 deletions
|
@ -169,6 +169,32 @@ impl ServoUrl {
|
|||
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Self, ()> {
|
||||
Ok(Self::from_url(Url::from_file_path(path)?))
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
|
||||
pub fn is_origin_trustworthy(&self) -> bool {
|
||||
// Step 1
|
||||
if !self.origin().is_tuple() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3
|
||||
if self.scheme() == "https" || self.scheme() == "wss" {
|
||||
true
|
||||
// Steps 4-5
|
||||
} else if self.host().is_some() {
|
||||
let host = self.host_str().unwrap();
|
||||
// Step 4
|
||||
if let Ok(ip_addr) = host.parse::<IpAddr>() {
|
||||
ip_addr.is_loopback()
|
||||
// Step 5
|
||||
} else {
|
||||
host == "localhost" || host.ends_with(".localhost")
|
||||
}
|
||||
// Step 6
|
||||
} else {
|
||||
self.scheme() == "file"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ServoUrl {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue