diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-04-05 14:42:59 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-04-05 14:42:59 +0200 |
commit | fb86bfebf406cfbe02bee1ad924e6b8e243453ef (patch) | |
tree | af1eaeeb7cef6b2f684cb780d974ec5f57b9bf07 /components/net | |
parent | 170bcfc03e18ffa3c504022f65c87e2189575020 (diff) | |
download | servo-fb86bfebf406cfbe02bee1ad924e6b8e243453ef.tar.gz servo-fb86bfebf406cfbe02bee1ad924e6b8e243453ef.zip |
Introduce HstsList::switch_known_hsts_host_domain_url_to_https
Diffstat (limited to 'components/net')
-rw-r--r-- | components/net/fetch/methods.rs | 11 | ||||
-rw-r--r-- | components/net/hsts.rs | 11 |
2 files changed, 13 insertions, 9 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 553c92cf79d..4e46700586d 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -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. diff --git a/components/net/hsts.rs b/components/net/hsts.rs index 2af1c01099e..3abf1c34d64 100644 --- a/components/net/hsts.rs +++ b/components/net/hsts.rs @@ -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(); + } + } } |