mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #8812 - jitendra29:support-withCredentials, r=jdm
M1504: Implement basic support for withCredentials API The pull request includes the following task: * Implemented basic network-level support by adding a member to LoadData that is used by http_loader.rs to conditionally exclude cookies from the HTTP request if the flag is false (default true) <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8812) <!-- Reviewable:end -->
This commit is contained in:
commit
217a55a785
4 changed files with 21 additions and 6 deletions
|
@ -504,7 +504,8 @@ fn request_must_be_secured(url: &Url, hsts_list: &Arc<RwLock<HSTSList>>) -> bool
|
||||||
pub fn modify_request_headers(headers: &mut Headers,
|
pub fn modify_request_headers(headers: &mut Headers,
|
||||||
doc_url: &Url,
|
doc_url: &Url,
|
||||||
user_agent: &str,
|
user_agent: &str,
|
||||||
cookie_jar: &Arc<RwLock<CookieStorage>>) {
|
cookie_jar: &Arc<RwLock<CookieStorage>>,
|
||||||
|
load_data: &LoadData) {
|
||||||
// Ensure that the host header is set from the original url
|
// Ensure that the host header is set from the original url
|
||||||
let host = Host {
|
let host = Host {
|
||||||
hostname: doc_url.serialize_host().unwrap(),
|
hostname: doc_url.serialize_host().unwrap(),
|
||||||
|
@ -515,14 +516,18 @@ pub fn modify_request_headers(headers: &mut Headers,
|
||||||
|
|
||||||
set_default_accept(headers);
|
set_default_accept(headers);
|
||||||
set_default_accept_encoding(headers);
|
set_default_accept_encoding(headers);
|
||||||
|
// https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch step 11
|
||||||
|
if load_data.credentials_flag {
|
||||||
set_request_cookies(doc_url.clone(), headers, cookie_jar);
|
set_request_cookies(doc_url.clone(), headers, cookie_jar);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_response_headers(response: &HttpResponse,
|
pub fn process_response_headers(response: &HttpResponse,
|
||||||
url: &Url,
|
url: &Url,
|
||||||
doc_url: &Url,
|
doc_url: &Url,
|
||||||
cookie_jar: &Arc<RwLock<CookieStorage>>,
|
cookie_jar: &Arc<RwLock<CookieStorage>>,
|
||||||
hsts_list: &Arc<RwLock<HSTSList>>) {
|
hsts_list: &Arc<RwLock<HSTSList>>,
|
||||||
|
load_data: &LoadData) {
|
||||||
info!("got HTTP response {}, headers:", response.status());
|
info!("got HTTP response {}, headers:", response.status());
|
||||||
if log_enabled!(log::LogLevel::Info) {
|
if log_enabled!(log::LogLevel::Info) {
|
||||||
for header in response.headers().iter() {
|
for header in response.headers().iter() {
|
||||||
|
@ -530,7 +535,10 @@ pub fn process_response_headers(response: &HttpResponse,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://fetch.spec.whatwg.org/#concept-http-network-fetch step 9
|
||||||
|
if load_data.credentials_flag {
|
||||||
set_cookies_from_response(doc_url.clone(), response, cookie_jar);
|
set_cookies_from_response(doc_url.clone(), response, cookie_jar);
|
||||||
|
}
|
||||||
update_sts_list_from_response(url, response, hsts_list);
|
update_sts_list_from_response(url, response, hsts_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,7 +612,7 @@ pub fn load<A>(load_data: LoadData,
|
||||||
load_data.preserved_headers.clone()
|
load_data.preserved_headers.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
modify_request_headers(&mut request_headers, &doc_url, &user_agent, &cookie_jar);
|
modify_request_headers(&mut request_headers, &doc_url, &user_agent, &cookie_jar, &load_data);
|
||||||
|
|
||||||
let request_id = uuid::Uuid::new_v4().to_simple_string();
|
let request_id = uuid::Uuid::new_v4().to_simple_string();
|
||||||
|
|
||||||
|
@ -674,7 +682,7 @@ pub fn load<A>(load_data: LoadData,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_response_headers(&response, &url, &doc_url, &cookie_jar, &hsts_list);
|
process_response_headers(&response, &url, &doc_url, &cookie_jar, &hsts_list, &load_data);
|
||||||
|
|
||||||
// --- Loop if there's a redirect
|
// --- Loop if there's a redirect
|
||||||
if response.status().class() == StatusClass::Redirection {
|
if response.status().class() == StatusClass::Redirection {
|
||||||
|
|
|
@ -137,6 +137,8 @@ pub struct LoadData {
|
||||||
pub data: Option<Vec<u8>>,
|
pub data: Option<Vec<u8>>,
|
||||||
pub cors: Option<ResourceCORSData>,
|
pub cors: Option<ResourceCORSData>,
|
||||||
pub pipeline_id: Option<PipelineId>,
|
pub pipeline_id: Option<PipelineId>,
|
||||||
|
// https://fetch.spec.whatwg.org/#concept-http-fetch step 4.3
|
||||||
|
pub credentials_flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoadData {
|
impl LoadData {
|
||||||
|
@ -149,6 +151,7 @@ impl LoadData {
|
||||||
data: None,
|
data: None,
|
||||||
cors: None,
|
cors: None,
|
||||||
pipeline_id: id,
|
pipeline_id: id,
|
||||||
|
credentials_flag: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,6 +516,9 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let pipeline_id = global.r().pipeline();
|
let pipeline_id = global.r().pipeline();
|
||||||
let mut load_data = LoadData::new(self.request_url.borrow().clone().unwrap(), Some(pipeline_id));
|
let mut load_data = LoadData::new(self.request_url.borrow().clone().unwrap(), Some(pipeline_id));
|
||||||
|
if load_data.url.origin().ne(&global.r().get_url().origin()) {
|
||||||
|
load_data.credentials_flag = self.WithCredentials();
|
||||||
|
}
|
||||||
load_data.data = extracted;
|
load_data.data = extracted;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -2013,6 +2013,7 @@ impl ScriptTask {
|
||||||
data: load_data.data,
|
data: load_data.data,
|
||||||
cors: None,
|
cors: None,
|
||||||
pipeline_id: Some(id),
|
pipeline_id: Some(id),
|
||||||
|
credentials_flag: true,
|
||||||
}, LoadConsumer::Listener(response_target), None)).unwrap();
|
}, LoadConsumer::Listener(response_target), None)).unwrap();
|
||||||
|
|
||||||
self.incomplete_loads.borrow_mut().push(incomplete);
|
self.incomplete_loads.borrow_mut().push(incomplete);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue