Introduce HstsList::switch_known_hsts_host_domain_url_to_https

This commit is contained in:
Anthony Ramine 2017-04-05 14:42:59 +02:00
parent 170bcfc03e
commit fb86bfebf4
3 changed files with 18 additions and 9 deletions

View file

@ -163,15 +163,8 @@ pub fn main_fetch(request: &mut Request,
// TODO: handle FTP URLs.
// Step 10.
if !request.current_url().is_secure_scheme() && request.current_url().domain().is_some() {
if context.state
.hsts_list
.read()
.unwrap()
.is_host_secure(request.current_url().domain().unwrap()) {
request.url_list.last_mut().unwrap().as_mut_url().set_scheme("https").unwrap();
}
}
context.state.hsts_list.read().unwrap().switch_known_hsts_host_domain_url_to_https(
request.current_url_mut());
// Step 11.
// Not applicable: see fetch_async.

View file

@ -6,6 +6,7 @@ use net_traits::IncludeSubdomains;
use net_traits::pub_domains::reg_suffix;
use serde_json;
use servo_config::resource_files::read_resource_file;
use servo_url::ServoUrl;
use std::collections::HashMap;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::from_utf8;
@ -134,4 +135,14 @@ impl HstsList {
}
}
}
/// Step 10 of https://fetch.spec.whatwg.org/#concept-main-fetch.
pub fn switch_known_hsts_host_domain_url_to_https(&self, url: &mut ServoUrl) {
if url.scheme() != "http" {
return;
}
if url.domain().map_or(false, |domain| self.is_host_secure(domain)) {
url.as_mut_url().set_scheme("https").unwrap();
}
}
}

View file

@ -330,6 +330,11 @@ impl Request {
self.url_list.last().unwrap().clone()
}
/// https://fetch.spec.whatwg.org/#concept-request-current-url
pub fn current_url_mut(&mut self) -> &mut ServoUrl {
self.url_list.last_mut().unwrap()
}
/// https://fetch.spec.whatwg.org/#navigation-request
pub fn is_navigation_request(&self) -> bool {
self.destination == Destination::Document