mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
updated basic auth cache to key off of url origin
This commit is contained in:
parent
e3d946bb29
commit
82e45a403f
4 changed files with 9 additions and 8 deletions
|
@ -827,7 +827,7 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
|
||||||
let mut authorization_value = None;
|
let mut authorization_value = None;
|
||||||
|
|
||||||
// Substep 4
|
// 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) {
|
if !http_request.use_url_credentials || !has_credentials(¤t_url) {
|
||||||
authorization_value = Some(basic);
|
authorization_value = Some(basic);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ use time;
|
||||||
use time::Tm;
|
use time::Tm;
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
||||||
use tinyfiledialogs;
|
use tinyfiledialogs;
|
||||||
use url::{Position, Url};
|
use url::{Position, Url, Origin};
|
||||||
use util::prefs::PREFS;
|
use util::prefs::PREFS;
|
||||||
use util::thread::spawn_named;
|
use util::thread::spawn_named;
|
||||||
use uuid;
|
use uuid;
|
||||||
|
@ -688,15 +688,15 @@ fn set_auth_header(headers: &mut Headers,
|
||||||
if let Some(auth) = auth_from_url(url) {
|
if let Some(auth) = auth_from_url(url) {
|
||||||
headers.set(auth);
|
headers.set(auth);
|
||||||
} else {
|
} 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));
|
headers.set(Authorization(basic));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, url: &Url) -> Option<Basic> {
|
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(url) {
|
if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(&origin.ascii_serialization()) {
|
||||||
let user_name = auth_entry.user_name.clone();
|
let user_name = auth_entry.user_name.clone();
|
||||||
let password = Some(auth_entry.password.clone());
|
let password = Some(auth_entry.password.clone());
|
||||||
Some(Basic { username: user_name, password: password })
|
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(),
|
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)]
|
#[derive(RustcDecodable, RustcEncodable, Clone)]
|
||||||
pub struct AuthCache {
|
pub struct AuthCache {
|
||||||
pub version: u32,
|
pub version: u32,
|
||||||
pub entries: HashMap<Url, AuthCacheEntry>,
|
pub entries: HashMap<String, AuthCacheEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CoreResourceManager {
|
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(),
|
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);
|
let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
|
||||||
load_data.credentials_flag = true;
|
load_data.credentials_flag = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue