Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update basic auth cache to key off of origin instead of url #13281

Merged
merged 4 commits into from Sep 16, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

updated basic auth cache to key off of url origin

  • Loading branch information
gilbertw1 committed Sep 16, 2016
commit 82e45a403f91571e5facbc1105472bdf4a96825b
@@ -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);
}
@@ -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);
}
}

@@ -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 {
@@ -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;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.