mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #14156 - frewsxcv:cors-capitalization, r=KiChjang
Update CORS naming from 'CORS' to 'Cors'. As per: https://aturon.github.io/style/naming/README.html#general-conventions-[rfc-#430] Acronyms should be considered one word and not all caps. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14156) <!-- Reviewable:end -->
This commit is contained in:
commit
e3f07dfa16
9 changed files with 67 additions and 67 deletions
|
@ -42,7 +42,7 @@ impl HeaderOrMethod {
|
||||||
|
|
||||||
/// An entry in the CORS cache
|
/// An entry in the CORS cache
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CORSCacheEntry {
|
pub struct CorsCacheEntry {
|
||||||
pub origin: Origin,
|
pub origin: Origin,
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
pub max_age: u32,
|
pub max_age: u32,
|
||||||
|
@ -51,10 +51,10 @@ pub struct CORSCacheEntry {
|
||||||
created: Timespec
|
created: Timespec
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CORSCacheEntry {
|
impl CorsCacheEntry {
|
||||||
fn new(origin: Origin, url: Url, max_age: u32, credentials: bool,
|
fn new(origin: Origin, url: Url, max_age: u32, credentials: bool,
|
||||||
header_or_method: HeaderOrMethod) -> CORSCacheEntry {
|
header_or_method: HeaderOrMethod) -> CorsCacheEntry {
|
||||||
CORSCacheEntry {
|
CorsCacheEntry {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
url: url,
|
url: url,
|
||||||
max_age: max_age,
|
max_age: max_age,
|
||||||
|
@ -65,7 +65,7 @@ impl CORSCacheEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_headers(cors_cache: &CORSCacheEntry, cors_req: &Request) -> bool {
|
fn match_headers(cors_cache: &CorsCacheEntry, cors_req: &Request) -> bool {
|
||||||
cors_cache.origin == *cors_req.origin.borrow() &&
|
cors_cache.origin == *cors_req.origin.borrow() &&
|
||||||
cors_cache.url == cors_req.current_url() &&
|
cors_cache.url == cors_req.current_url() &&
|
||||||
(cors_cache.credentials || cors_req.credentials_mode != CredentialsMode::Include)
|
(cors_cache.credentials || cors_req.credentials_mode != CredentialsMode::Include)
|
||||||
|
@ -73,43 +73,43 @@ fn match_headers(cors_cache: &CORSCacheEntry, cors_req: &Request) -> bool {
|
||||||
|
|
||||||
/// A simple, vector-based CORS Cache
|
/// A simple, vector-based CORS Cache
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CORSCache(Vec<CORSCacheEntry>);
|
pub struct CorsCache(Vec<CorsCacheEntry>);
|
||||||
|
|
||||||
impl CORSCache {
|
impl CorsCache {
|
||||||
pub fn new() -> CORSCache {
|
pub fn new() -> CorsCache {
|
||||||
CORSCache(vec![])
|
CorsCache(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_entry_by_header<'a>(&'a mut self, request: &Request,
|
fn find_entry_by_header<'a>(&'a mut self, request: &Request,
|
||||||
header_name: &str) -> Option<&'a mut CORSCacheEntry> {
|
header_name: &str) -> Option<&'a mut CorsCacheEntry> {
|
||||||
self.cleanup();
|
self.cleanup();
|
||||||
self.0.iter_mut().find(|e| match_headers(e, request) && e.header_or_method.match_header(header_name))
|
self.0.iter_mut().find(|e| match_headers(e, request) && e.header_or_method.match_header(header_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_entry_by_method<'a>(&'a mut self, request: &Request,
|
fn find_entry_by_method<'a>(&'a mut self, request: &Request,
|
||||||
method: Method) -> Option<&'a mut CORSCacheEntry> {
|
method: Method) -> Option<&'a mut CorsCacheEntry> {
|
||||||
// we can take the method from CORSRequest itself
|
// we can take the method from CorSRequest itself
|
||||||
self.cleanup();
|
self.cleanup();
|
||||||
self.0.iter_mut().find(|e| match_headers(e, request) && e.header_or_method.match_method(&method))
|
self.0.iter_mut().find(|e| match_headers(e, request) && e.header_or_method.match_method(&method))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Clear the cache](https://fetch.spec.whatwg.org/#concept-cache-clear)
|
/// [Clear the cache](https://fetch.spec.whatwg.org/#concept-cache-clear)
|
||||||
pub fn clear(&mut self, request: &Request) {
|
pub fn clear(&mut self, request: &Request) {
|
||||||
let CORSCache(buf) = self.clone();
|
let CorsCache(buf) = self.clone();
|
||||||
let new_buf: Vec<CORSCacheEntry> =
|
let new_buf: Vec<CorsCacheEntry> =
|
||||||
buf.into_iter().filter(|e| e.origin == *request.origin.borrow() &&
|
buf.into_iter().filter(|e| e.origin == *request.origin.borrow() &&
|
||||||
request.current_url() == e.url).collect();
|
request.current_url() == e.url).collect();
|
||||||
*self = CORSCache(new_buf);
|
*self = CorsCache(new_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove old entries
|
/// Remove old entries
|
||||||
pub fn cleanup(&mut self) {
|
pub fn cleanup(&mut self) {
|
||||||
let CORSCache(buf) = self.clone();
|
let CorsCache(buf) = self.clone();
|
||||||
let now = time::now().to_timespec();
|
let now = time::now().to_timespec();
|
||||||
let new_buf: Vec<CORSCacheEntry> = buf.into_iter()
|
let new_buf: Vec<CorsCacheEntry> = buf.into_iter()
|
||||||
.filter(|e| now.sec < e.created.sec + e.max_age as i64)
|
.filter(|e| now.sec < e.created.sec + e.max_age as i64)
|
||||||
.collect();
|
.collect();
|
||||||
*self = CORSCache(new_buf);
|
*self = CorsCache(new_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if an entry with a
|
/// Returns true if an entry with a
|
||||||
|
@ -127,7 +127,7 @@ impl CORSCache {
|
||||||
match self.find_entry_by_header(&request, header_name).map(|e| e.max_age = new_max_age) {
|
match self.find_entry_by_header(&request, header_name).map(|e| e.max_age = new_max_age) {
|
||||||
Some(_) => true,
|
Some(_) => true,
|
||||||
None => {
|
None => {
|
||||||
self.insert(CORSCacheEntry::new(request.origin.borrow().clone(), request.current_url(), new_max_age,
|
self.insert(CorsCacheEntry::new(request.origin.borrow().clone(), request.current_url(), new_max_age,
|
||||||
request.credentials_mode == CredentialsMode::Include,
|
request.credentials_mode == CredentialsMode::Include,
|
||||||
HeaderOrMethod::HeaderData(header_name.to_owned())));
|
HeaderOrMethod::HeaderData(header_name.to_owned())));
|
||||||
false
|
false
|
||||||
|
@ -149,7 +149,7 @@ impl CORSCache {
|
||||||
match self.find_entry_by_method(&request, method.clone()).map(|e| e.max_age = new_max_age) {
|
match self.find_entry_by_method(&request, method.clone()).map(|e| e.max_age = new_max_age) {
|
||||||
Some(_) => true,
|
Some(_) => true,
|
||||||
None => {
|
None => {
|
||||||
self.insert(CORSCacheEntry::new(request.origin.borrow().clone(), request.current_url(), new_max_age,
|
self.insert(CorsCacheEntry::new(request.origin.borrow().clone(), request.current_url(), new_max_age,
|
||||||
request.credentials_mode == CredentialsMode::Include,
|
request.credentials_mode == CredentialsMode::Include,
|
||||||
HeaderOrMethod::MethodData(method)));
|
HeaderOrMethod::MethodData(method)));
|
||||||
false
|
false
|
||||||
|
@ -158,7 +158,7 @@ impl CORSCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert an entry
|
/// Insert an entry
|
||||||
pub fn insert(&mut self, entry: CORSCacheEntry) {
|
pub fn insert(&mut self, entry: CorsCacheEntry) {
|
||||||
self.cleanup();
|
self.cleanup();
|
||||||
self.0.push(entry);
|
self.0.push(entry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use blob_loader::load_blob_sync;
|
||||||
use connector::create_http_connector;
|
use connector::create_http_connector;
|
||||||
use data_loader::decode;
|
use data_loader::decode;
|
||||||
use devtools_traits::DevtoolsControlMsg;
|
use devtools_traits::DevtoolsControlMsg;
|
||||||
use fetch::cors_cache::CORSCache;
|
use fetch::cors_cache::CorsCache;
|
||||||
use filemanager_thread::{FileManager, UIProvider};
|
use filemanager_thread::{FileManager, UIProvider};
|
||||||
use http_loader::{HttpState, set_default_accept_encoding, set_default_accept_language, set_request_cookies};
|
use http_loader::{HttpState, set_default_accept_encoding, set_default_accept_language, set_request_cookies};
|
||||||
use http_loader::{NetworkHttpRequestFactory, ReadResult, StreamedResponse, obtain_response, read_block};
|
use http_loader::{NetworkHttpRequestFactory, ReadResult, StreamedResponse, obtain_response, read_block};
|
||||||
|
@ -65,11 +65,11 @@ pub fn fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
context: &FetchContext<UI>)
|
context: &FetchContext<UI>)
|
||||||
-> Response {
|
-> Response {
|
||||||
fetch_with_cors_cache(request, &mut CORSCache::new(), target, context)
|
fetch_with_cors_cache(request, &mut CorsCache::new(), target, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
|
pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
context: &FetchContext<UI>)
|
context: &FetchContext<UI>)
|
||||||
-> Response {
|
-> Response {
|
||||||
|
@ -136,7 +136,7 @@ pub fn fetch_with_cors_cache<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
/// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch)
|
/// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch)
|
||||||
fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
cors_flag: bool,
|
cors_flag: bool,
|
||||||
recursive_flag: bool,
|
recursive_flag: bool,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
|
@ -213,7 +213,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
} else if request.mode == RequestMode::SameOrigin {
|
} else if request.mode == RequestMode::SameOrigin {
|
||||||
Response::network_error(NetworkError::Internal("Cross-origin response".into()))
|
Response::network_error(NetworkError::Internal("Cross-origin response".into()))
|
||||||
|
|
||||||
} else if request.mode == RequestMode::NoCORS {
|
} else if request.mode == RequestMode::NoCors {
|
||||||
request.response_tainting.set(ResponseTainting::Opaque);
|
request.response_tainting.set(ResponseTainting::Opaque);
|
||||||
basic_fetch(request.clone(), cache, target, done_chan, context)
|
basic_fetch(request.clone(), cache, target, done_chan, context)
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
(request.unsafe_request &&
|
(request.unsafe_request &&
|
||||||
(!is_simple_method(&request.method.borrow()) ||
|
(!is_simple_method(&request.method.borrow()) ||
|
||||||
request.headers.borrow().iter().any(|h| !is_simple_header(&h)))) {
|
request.headers.borrow().iter().any(|h| !is_simple_header(&h)))) {
|
||||||
request.response_tainting.set(ResponseTainting::CORSTainting);
|
request.response_tainting.set(ResponseTainting::CorsTainting);
|
||||||
request.redirect_mode.set(RedirectMode::Error);
|
request.redirect_mode.set(RedirectMode::Error);
|
||||||
let response = http_fetch(request.clone(), cache, true, true, false,
|
let response = http_fetch(request.clone(), cache, true, true, false,
|
||||||
target, done_chan, context);
|
target, done_chan, context);
|
||||||
|
@ -234,7 +234,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
response
|
response
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
request.response_tainting.set(ResponseTainting::CORSTainting);
|
request.response_tainting.set(ResponseTainting::CorsTainting);
|
||||||
http_fetch(request.clone(), cache, true, false, false, target, done_chan, context)
|
http_fetch(request.clone(), cache, true, false, false, target, done_chan, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
let response = if response.response_type == ResponseType::Default {
|
let response = if response.response_type == ResponseType::Default {
|
||||||
let response_type = match request.response_tainting.get() {
|
let response_type = match request.response_tainting.get() {
|
||||||
ResponseTainting::Basic => ResponseType::Basic,
|
ResponseTainting::Basic => ResponseType::Basic,
|
||||||
ResponseTainting::CORSTainting => ResponseType::CORS,
|
ResponseTainting::CorsTainting => ResponseType::Cors,
|
||||||
ResponseTainting::Opaque => ResponseType::Opaque,
|
ResponseTainting::Opaque => ResponseType::Opaque,
|
||||||
};
|
};
|
||||||
response.to_filtered(response_type)
|
response.to_filtered(response_type)
|
||||||
|
@ -400,7 +400,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
/// [Basic fetch](https://fetch.spec.whatwg.org#basic-fetch)
|
/// [Basic fetch](https://fetch.spec.whatwg.org#basic-fetch)
|
||||||
fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
done_chan: &mut DoneChannel,
|
done_chan: &mut DoneChannel,
|
||||||
context: &FetchContext<UI>)
|
context: &FetchContext<UI>)
|
||||||
|
@ -492,7 +492,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
||||||
fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
cors_flag: bool,
|
cors_flag: bool,
|
||||||
cors_preflight_flag: bool,
|
cors_preflight_flag: bool,
|
||||||
authentication_fetch_flag: bool,
|
authentication_fetch_flag: bool,
|
||||||
|
@ -519,7 +519,7 @@ fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
// Substep 3
|
// Substep 3
|
||||||
if (res.response_type == ResponseType::Opaque &&
|
if (res.response_type == ResponseType::Opaque &&
|
||||||
request.mode != RequestMode::NoCORS) ||
|
request.mode != RequestMode::NoCors) ||
|
||||||
(res.response_type == ResponseType::OpaqueRedirect &&
|
(res.response_type == ResponseType::OpaqueRedirect &&
|
||||||
request.redirect_mode.get() != RedirectMode::Manual) ||
|
request.redirect_mode.get() != RedirectMode::Manual) ||
|
||||||
(res.url_list.borrow().len() > 1 &&
|
(res.url_list.borrow().len() > 1 &&
|
||||||
|
@ -667,7 +667,7 @@ fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
|
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
|
||||||
fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
response: Response,
|
response: Response,
|
||||||
cors_flag: bool,
|
cors_flag: bool,
|
||||||
target: &mut Target,
|
target: &mut Target,
|
||||||
|
@ -713,7 +713,7 @@ fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
};
|
};
|
||||||
let has_credentials = has_credentials(&location_url);
|
let has_credentials = has_credentials(&location_url);
|
||||||
|
|
||||||
if request.mode == RequestMode::CORSMode && !same_origin && has_credentials {
|
if request.mode == RequestMode::CorsMode && !same_origin && has_credentials {
|
||||||
return Response::network_error(NetworkError::Internal("Cross-origin credentials check failed".into()));
|
return Response::network_error(NetworkError::Internal("Cross-origin credentials check failed".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,7 +1158,7 @@ fn http_network_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
|
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
|
||||||
fn cors_preflight_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
fn cors_preflight_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
cache: &mut CORSCache,
|
cache: &mut CorsCache,
|
||||||
context: &FetchContext<UI>)
|
context: &FetchContext<UI>)
|
||||||
-> Response {
|
-> Response {
|
||||||
// Step 1
|
// Step 1
|
||||||
|
|
|
@ -152,7 +152,7 @@ pub struct LoadData {
|
||||||
/// Unused in fetch
|
/// Unused in fetch
|
||||||
pub preserved_headers: Headers,
|
pub preserved_headers: Headers,
|
||||||
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
|
// https://fetch.spec.whatwg.org/#concept-http-fetch step 4.3
|
||||||
pub credentials_flag: bool,
|
pub credentials_flag: bool,
|
||||||
|
@ -472,7 +472,7 @@ pub struct LoadResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
|
#[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
|
||||||
pub struct ResourceCORSData {
|
pub struct ResourceCorsData {
|
||||||
/// CORS Preflight flag
|
/// CORS Preflight flag
|
||||||
pub preflight: bool,
|
pub preflight: bool,
|
||||||
/// Origin of CORS Request
|
/// Origin of CORS Request
|
||||||
|
|
|
@ -57,8 +57,8 @@ pub enum Referrer {
|
||||||
pub enum RequestMode {
|
pub enum RequestMode {
|
||||||
Navigate,
|
Navigate,
|
||||||
SameOrigin,
|
SameOrigin,
|
||||||
NoCORS,
|
NoCors,
|
||||||
CORSMode
|
CorsMode
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request [credentials mode](https://fetch.spec.whatwg.org/#concept-request-credentials-mode)
|
/// Request [credentials mode](https://fetch.spec.whatwg.org/#concept-request-credentials-mode)
|
||||||
|
@ -92,7 +92,7 @@ pub enum RedirectMode {
|
||||||
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
||||||
pub enum ResponseTainting {
|
pub enum ResponseTainting {
|
||||||
Basic,
|
Basic,
|
||||||
CORSTainting,
|
CorsTainting,
|
||||||
Opaque
|
Opaque
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ pub enum Window {
|
||||||
|
|
||||||
/// [CORS settings attribute](https://html.spec.whatwg.org/multipage/#attr-crossorigin-anonymous)
|
/// [CORS settings attribute](https://html.spec.whatwg.org/multipage/#attr-crossorigin-anonymous)
|
||||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum CORSSettings {
|
pub enum CorsSettings {
|
||||||
Anonymous,
|
Anonymous,
|
||||||
UseCredentials
|
UseCredentials
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl Default for RequestInit {
|
||||||
type_: Type::None,
|
type_: Type::None,
|
||||||
destination: Destination::None,
|
destination: Destination::None,
|
||||||
synchronous: false,
|
synchronous: false,
|
||||||
mode: RequestMode::NoCORS,
|
mode: RequestMode::NoCors,
|
||||||
use_cors_preflight: false,
|
use_cors_preflight: false,
|
||||||
credentials_mode: CredentialsMode::Omit,
|
credentials_mode: CredentialsMode::Omit,
|
||||||
use_url_credentials: false,
|
use_url_credentials: false,
|
||||||
|
@ -232,7 +232,7 @@ impl Request {
|
||||||
referrer_policy: Cell::new(None),
|
referrer_policy: Cell::new(None),
|
||||||
pipeline_id: Cell::new(pipeline_id),
|
pipeline_id: Cell::new(pipeline_id),
|
||||||
synchronous: false,
|
synchronous: false,
|
||||||
mode: RequestMode::NoCORS,
|
mode: RequestMode::NoCors,
|
||||||
use_cors_preflight: false,
|
use_cors_preflight: false,
|
||||||
credentials_mode: CredentialsMode::Omit,
|
credentials_mode: CredentialsMode::Omit,
|
||||||
use_url_credentials: false,
|
use_url_credentials: false,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use url::Url;
|
||||||
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize, HeapSizeOf)]
|
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize, HeapSizeOf)]
|
||||||
pub enum ResponseType {
|
pub enum ResponseType {
|
||||||
Basic,
|
Basic,
|
||||||
CORS,
|
Cors,
|
||||||
Default,
|
Default,
|
||||||
Error(NetworkError),
|
Error(NetworkError),
|
||||||
Opaque,
|
Opaque,
|
||||||
|
@ -202,7 +202,7 @@ impl Response {
|
||||||
response.headers = headers;
|
response.headers = headers;
|
||||||
},
|
},
|
||||||
|
|
||||||
ResponseType::CORS => {
|
ResponseType::Cors => {
|
||||||
let access = old_headers.get::<AccessControlExposeHeaders>();
|
let access = old_headers.get::<AccessControlExposeHeaders>();
|
||||||
let allowed_headers = access.as_ref().map(|v| &v[..]).unwrap_or(&[]);
|
let allowed_headers = access.as_ref().map(|v| &v[..]).unwrap_or(&[]);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ use ipc_channel::ipc;
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError};
|
use net_traits::{FetchMetadata, FetchResponseListener, Metadata, NetworkError};
|
||||||
use net_traits::request::{CORSSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType};
|
use net_traits::request::{CorsSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType};
|
||||||
use network_listener::{NetworkListener, PreInvoke};
|
use network_listener::{NetworkListener, PreInvoke};
|
||||||
use servo_atoms::Atom;
|
use servo_atoms::Atom;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
@ -220,7 +220,7 @@ impl PreInvoke for ScriptContext {}
|
||||||
/// https://html.spec.whatwg.org/multipage/#fetch-a-classic-script
|
/// https://html.spec.whatwg.org/multipage/#fetch-a-classic-script
|
||||||
fn fetch_a_classic_script(script: &HTMLScriptElement,
|
fn fetch_a_classic_script(script: &HTMLScriptElement,
|
||||||
url: Url,
|
url: Url,
|
||||||
cors_setting: Option<CORSSettings>,
|
cors_setting: Option<CorsSettings>,
|
||||||
character_encoding: EncodingRef) {
|
character_encoding: EncodingRef) {
|
||||||
let doc = document_from_node(script);
|
let doc = document_from_node(script);
|
||||||
|
|
||||||
|
@ -232,13 +232,13 @@ fn fetch_a_classic_script(script: &HTMLScriptElement,
|
||||||
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
|
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
|
||||||
// Step 1
|
// Step 1
|
||||||
mode: match cors_setting {
|
mode: match cors_setting {
|
||||||
Some(_) => RequestMode::CORSMode,
|
Some(_) => RequestMode::CorsMode,
|
||||||
None => RequestMode::NoCORS,
|
None => RequestMode::NoCors,
|
||||||
},
|
},
|
||||||
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
|
// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
|
||||||
// Step 3-4
|
// Step 3-4
|
||||||
credentials_mode: match cors_setting {
|
credentials_mode: match cors_setting {
|
||||||
Some(CORSSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
|
Some(CorsSettings::Anonymous) => CredentialsMode::CredentialsSameOrigin,
|
||||||
_ => CredentialsMode::Include,
|
_ => CredentialsMode::Include,
|
||||||
},
|
},
|
||||||
origin: doc.url().clone(),
|
origin: doc.url().clone(),
|
||||||
|
@ -359,8 +359,8 @@ impl HTMLScriptElement {
|
||||||
|
|
||||||
// Step 14.
|
// Step 14.
|
||||||
let cors_setting = match self.GetCrossOrigin() {
|
let cors_setting = match self.GetCrossOrigin() {
|
||||||
Some(ref s) if *s == "anonymous" => Some(CORSSettings::Anonymous),
|
Some(ref s) if *s == "anonymous" => Some(CorsSettings::Anonymous),
|
||||||
Some(ref s) if *s == "use-credentials" => Some(CORSSettings::UseCredentials),
|
Some(ref s) if *s == "use-credentials" => Some(CorsSettings::UseCredentials),
|
||||||
None => None,
|
None => None,
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl Request {
|
||||||
url,
|
url,
|
||||||
false);
|
false);
|
||||||
// Step 5.5
|
// Step 5.5
|
||||||
fallback_mode = Some(NetTraitsRequestMode::CORSMode);
|
fallback_mode = Some(NetTraitsRequestMode::CorsMode);
|
||||||
// Step 5.6
|
// Step 5.6
|
||||||
fallback_credentials = Some(NetTraitsRequestCredentials::Omit);
|
fallback_credentials = Some(NetTraitsRequestCredentials::Omit);
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ impl Request {
|
||||||
// deep copied headers in Step 27.
|
// deep copied headers in Step 27.
|
||||||
|
|
||||||
// Step 30
|
// Step 30
|
||||||
if r.request.borrow().mode == NetTraitsRequestMode::NoCORS {
|
if r.request.borrow().mode == NetTraitsRequestMode::NoCors {
|
||||||
let borrowed_request = r.request.borrow();
|
let borrowed_request = r.request.borrow();
|
||||||
// Step 30.1
|
// Step 30.1
|
||||||
if !is_cors_safelisted_method(&borrowed_request.method.borrow()) {
|
if !is_cors_safelisted_method(&borrowed_request.method.borrow()) {
|
||||||
|
@ -814,8 +814,8 @@ impl Into<NetTraitsRequestMode> for RequestMode {
|
||||||
match self {
|
match self {
|
||||||
RequestMode::Navigate => NetTraitsRequestMode::Navigate,
|
RequestMode::Navigate => NetTraitsRequestMode::Navigate,
|
||||||
RequestMode::Same_origin => NetTraitsRequestMode::SameOrigin,
|
RequestMode::Same_origin => NetTraitsRequestMode::SameOrigin,
|
||||||
RequestMode::No_cors => NetTraitsRequestMode::NoCORS,
|
RequestMode::No_cors => NetTraitsRequestMode::NoCors,
|
||||||
RequestMode::Cors => NetTraitsRequestMode::CORSMode,
|
RequestMode::Cors => NetTraitsRequestMode::CorsMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -825,8 +825,8 @@ impl Into<RequestMode> for NetTraitsRequestMode {
|
||||||
match self {
|
match self {
|
||||||
NetTraitsRequestMode::Navigate => RequestMode::Navigate,
|
NetTraitsRequestMode::Navigate => RequestMode::Navigate,
|
||||||
NetTraitsRequestMode::SameOrigin => RequestMode::Same_origin,
|
NetTraitsRequestMode::SameOrigin => RequestMode::Same_origin,
|
||||||
NetTraitsRequestMode::NoCORS => RequestMode::No_cors,
|
NetTraitsRequestMode::NoCors => RequestMode::No_cors,
|
||||||
NetTraitsRequestMode::CORSMode => RequestMode::Cors,
|
NetTraitsRequestMode::CorsMode => RequestMode::Cors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -590,7 +590,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
// https://github.com/whatwg/xhr/issues/71
|
// https://github.com/whatwg/xhr/issues/71
|
||||||
destination: Destination::None,
|
destination: Destination::None,
|
||||||
synchronous: self.sync.get(),
|
synchronous: self.sync.get(),
|
||||||
mode: RequestMode::CORSMode,
|
mode: RequestMode::CorsMode,
|
||||||
use_cors_preflight: has_handlers,
|
use_cors_preflight: has_handlers,
|
||||||
credentials_mode: credentials_mode,
|
credentials_mode: credentials_mode,
|
||||||
use_url_credentials: use_url_credentials,
|
use_url_credentials: use_url_credentials,
|
||||||
|
|
|
@ -20,7 +20,7 @@ use hyper::server::{Request as HyperRequest, Response as HyperResponse};
|
||||||
use hyper::status::StatusCode;
|
use hyper::status::StatusCode;
|
||||||
use hyper::uri::RequestUri;
|
use hyper::uri::RequestUri;
|
||||||
use msg::constellation_msg::TEST_PIPELINE_ID;
|
use msg::constellation_msg::TEST_PIPELINE_ID;
|
||||||
use net::fetch::cors_cache::CORSCache;
|
use net::fetch::cors_cache::CorsCache;
|
||||||
use net::fetch::methods::{fetch, fetch_with_cors_cache};
|
use net::fetch::methods::{fetch, fetch_with_cors_cache};
|
||||||
use net_traits::ReferrerPolicy;
|
use net_traits::ReferrerPolicy;
|
||||||
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
|
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
|
||||||
|
@ -189,7 +189,7 @@ fn test_cors_preflight_fetch() {
|
||||||
*request.referrer.borrow_mut() = Referrer::ReferrerUrl(target_url);
|
*request.referrer.borrow_mut() = Referrer::ReferrerUrl(target_url);
|
||||||
*request.referrer_policy.get_mut() = Some(ReferrerPolicy::Origin);
|
*request.referrer_policy.get_mut() = Some(ReferrerPolicy::Origin);
|
||||||
request.use_cors_preflight = true;
|
request.use_cors_preflight = true;
|
||||||
request.mode = RequestMode::CORSMode;
|
request.mode = RequestMode::CorsMode;
|
||||||
let fetch_response = fetch_sync(request, None);
|
let fetch_response = fetch_sync(request, None);
|
||||||
let _ = server.close();
|
let _ = server.close();
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ fn test_cors_preflight_cache_fetch() {
|
||||||
static ACK: &'static [u8] = b"ACK";
|
static ACK: &'static [u8] = b"ACK";
|
||||||
let state = Arc::new(AtomicUsize::new(0));
|
let state = Arc::new(AtomicUsize::new(0));
|
||||||
let counter = state.clone();
|
let counter = state.clone();
|
||||||
let mut cache = CORSCache::new();
|
let mut cache = CorsCache::new();
|
||||||
let handler = move |request: HyperRequest, mut response: HyperResponse| {
|
let handler = move |request: HyperRequest, mut response: HyperResponse| {
|
||||||
if request.method == Method::Options && state.clone().fetch_add(1, Ordering::SeqCst) == 0 {
|
if request.method == Method::Options && state.clone().fetch_add(1, Ordering::SeqCst) == 0 {
|
||||||
assert!(request.headers.has::<AccessControlRequestMethod>());
|
assert!(request.headers.has::<AccessControlRequestMethod>());
|
||||||
|
@ -226,7 +226,7 @@ fn test_cors_preflight_cache_fetch() {
|
||||||
let mut request = Request::new(url.clone(), Some(origin.clone()), false, None);
|
let mut request = Request::new(url.clone(), Some(origin.clone()), false, None);
|
||||||
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
||||||
request.use_cors_preflight = true;
|
request.use_cors_preflight = true;
|
||||||
request.mode = RequestMode::CORSMode;
|
request.mode = RequestMode::CorsMode;
|
||||||
let wrapped_request0 = Rc::new(request.clone());
|
let wrapped_request0 = Rc::new(request.clone());
|
||||||
let wrapped_request1 = Rc::new(request);
|
let wrapped_request1 = Rc::new(request);
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ fn test_cors_preflight_fetch_network_error() {
|
||||||
*request.method.borrow_mut() = Method::Extension("CHICKEN".to_owned());
|
*request.method.borrow_mut() = Method::Extension("CHICKEN".to_owned());
|
||||||
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
||||||
request.use_cors_preflight = true;
|
request.use_cors_preflight = true;
|
||||||
request.mode = RequestMode::CORSMode;
|
request.mode = RequestMode::CorsMode;
|
||||||
let fetch_response = fetch_sync(request, None);
|
let fetch_response = fetch_sync(request, None);
|
||||||
let _ = server.close();
|
let _ = server.close();
|
||||||
|
|
||||||
|
@ -345,12 +345,12 @@ fn test_fetch_response_is_cors_filtered() {
|
||||||
let origin = Origin::Origin(UrlOrigin::new_opaque());
|
let origin = Origin::Origin(UrlOrigin::new_opaque());
|
||||||
let mut request = Request::new(url, Some(origin), false, None);
|
let mut request = Request::new(url, Some(origin), false, None);
|
||||||
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
*request.referrer.borrow_mut() = Referrer::NoReferrer;
|
||||||
request.mode = RequestMode::CORSMode;
|
request.mode = RequestMode::CorsMode;
|
||||||
let fetch_response = fetch_sync(request, None);
|
let fetch_response = fetch_sync(request, None);
|
||||||
let _ = server.close();
|
let _ = server.close();
|
||||||
|
|
||||||
assert!(!fetch_response.is_network_error());
|
assert!(!fetch_response.is_network_error());
|
||||||
assert_eq!(fetch_response.response_type, ResponseType::CORS);
|
assert_eq!(fetch_response.response_type, ResponseType::Cors);
|
||||||
|
|
||||||
let headers = fetch_response.headers;
|
let headers = fetch_response.headers;
|
||||||
assert!(headers.has::<CacheControl>());
|
assert!(headers.has::<CacheControl>());
|
||||||
|
@ -630,7 +630,7 @@ fn test_fetch_redirect_updates_method() {
|
||||||
|
|
||||||
fn response_is_done(response: &Response) -> bool {
|
fn response_is_done(response: &Response) -> bool {
|
||||||
let response_complete = match response.response_type {
|
let response_complete = match response.response_type {
|
||||||
ResponseType::Default | ResponseType::Basic | ResponseType::CORS => {
|
ResponseType::Default | ResponseType::Basic | ResponseType::Cors => {
|
||||||
(*response.body.lock().unwrap()).is_done()
|
(*response.body.lock().unwrap()).is_done()
|
||||||
}
|
}
|
||||||
// if the internal response cannot have a body, it shouldn't block the "done" state
|
// if the internal response cannot have a body, it shouldn't block the "done" state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue