updated basic auth cache to key off of url origin

This commit is contained in:
Bryan Gilbert 2016-09-14 16:08:36 -04:00
parent e3d946bb29
commit 82e45a403f
4 changed files with 9 additions and 8 deletions

View file

@ -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, &current_url) {
if let Some(basic) = auth_from_cache(&context.state.auth_cache, &current_url.origin()) {
if !http_request.use_url_credentials || !has_credentials(&current_url) {
authorization_value = Some(basic);
}

View file

@ -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);
}
}

View file

@ -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 {