diff options
author | Corey Farwell <coreyf@rwell.org> | 2016-04-17 12:25:17 -0400 |
---|---|---|
committer | Corey Farwell <coreyf@rwell.org> | 2016-04-17 14:12:07 -0400 |
commit | faa3d8724b9d45bc15f03b3fe46058daf565cd21 (patch) | |
tree | e8fef660a92624c6a6a4978fb26d79b32b0bf041 /components/net/hsts.rs | |
parent | d3b8b6472bbc0c99a04e7e9e8d3b74ae446a8716 (diff) | |
download | servo-faa3d8724b9d45bc15f03b3fe46058daf565cd21.tar.gz servo-faa3d8724b9d45bc15f03b3fe46058daf565cd21.zip |
Refactor Servo HSTS file loading, hard-fail if can't load.
Use constructor pattern instead of separate utility function.
Instead of allowing the Servo HSTS file loading to silently fail, we
should expect that file to always exist and be formatted correctly.
Diffstat (limited to 'components/net/hsts.rs')
-rw-r--r-- | components/net/hsts.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/components/net/hsts.rs b/components/net/hsts.rs index 946bb19c294..70c301a2ed8 100644 --- a/components/net/hsts.rs +++ b/components/net/hsts.rs @@ -70,6 +70,13 @@ impl HSTSList { .and_then(|c| decode(c).ok()) } + pub fn from_servo_preload() -> HSTSList { + let file_bytes = read_resource_file("hsts_preload.json") + .expect("Could not find Servo HSTS preload file"); + HSTSList::from_preload(&file_bytes) + .expect("Servo HSTS preload file is invalid") + } + pub fn is_host_secure(&self, host: &str) -> bool { // TODO - Should this be faster than O(n)? The HSTS list is only a few // hundred or maybe thousand entries... @@ -114,12 +121,6 @@ impl HSTSList { } } -pub fn preload_hsts_domains() -> Option<HSTSList> { - read_resource_file("hsts_preload.json") - .ok() - .and_then(|bytes| HSTSList::from_preload(&bytes)) -} - pub fn secure_url(url: &Url) -> Url { if &*url.scheme == "http" { let mut secure_url = url.clone(); |