diff options
-rw-r--r-- | components/net/fetch/methods.rs | 2 | ||||
-rw-r--r-- | components/net/http_loader.rs | 11 | ||||
-rw-r--r-- | components/net/resource_thread.rs | 2 | ||||
-rw-r--r-- | tests/unit/net/http_loader.rs | 2 |
4 files changed, 9 insertions, 8 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index b9caa134712..819c85ef564 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -827,7 +827,7 @@ fn http_network_or_cache_fetch(request: Rc<Request>, let mut authorization_value = None; // Substep 4 - if let Some(basic) = auth_from_cache(&context.state.auth_cache, ¤t_url) { + if let Some(basic) = auth_from_cache(&context.state.auth_cache, ¤t_url.origin()) { if !http_request.use_url_credentials || !has_credentials(¤t_url) { authorization_value = Some(basic); } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index d104521c48b..ec73a5e39a9 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -52,7 +52,7 @@ use time; use time::Tm; #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] use tinyfiledialogs; -use url::{Position, Url}; +use url::{Position, Url, Origin}; use util::prefs::PREFS; use util::thread::spawn_named; use uuid; @@ -688,15 +688,15 @@ fn set_auth_header(headers: &mut Headers, if let Some(auth) = auth_from_url(url) { headers.set(auth); } else { - if let Some(basic) = auth_from_cache(auth_cache, url) { + if let Some(basic) = auth_from_cache(auth_cache, &url.origin()) { headers.set(Authorization(basic)); } } } } -pub fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, url: &Url) -> Option<Basic> { - if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(url) { +pub fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, origin: &Origin) -> Option<Basic> { + if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(&origin.ascii_serialization()) { let user_name = auth_entry.user_name.clone(); let password = Some(auth_entry.password.clone()); Some(Basic { username: user_name, password: password }) @@ -1023,7 +1023,8 @@ pub fn load<A, B>(load_data: &LoadData, password: auth_header.password.to_owned().unwrap(), }; - http_state.auth_cache.write().unwrap().entries.insert(doc_url.clone(), auth_entry); + let serialized_origin = doc_url.origin().ascii_serialization(); + http_state.auth_cache.write().unwrap().entries.insert(serialized_origin, auth_entry); } } diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index d04e4d9b4c0..60699ca84f9 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -466,7 +466,7 @@ impl AuthCache { #[derive(RustcDecodable, RustcEncodable, Clone)] pub struct AuthCache { pub version: u32, - pub entries: HashMap<Url, AuthCacheEntry>, + pub entries: HashMap<String, AuthCacheEntry>, } pub struct CoreResourceManager { diff --git a/tests/unit/net/http_loader.rs b/tests/unit/net/http_loader.rs index 15bd6b8fd25..f22dc001c6e 100644 --- a/tests/unit/net/http_loader.rs +++ b/tests/unit/net/http_loader.rs @@ -1533,7 +1533,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() { password: "test".to_owned(), }; - http_state.auth_cache.write().unwrap().entries.insert(url.clone(), auth_entry); + http_state.auth_cache.write().unwrap().entries.insert(url.origin().clone(), auth_entry); let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest); load_data.credentials_flag = true; |