mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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.
This commit is contained in:
parent
35f328d717
commit
bf8752ac9e
9 changed files with 67 additions and 67 deletions
|
@ -42,7 +42,7 @@ impl HeaderOrMethod {
|
|||
|
||||
/// An entry in the CORS cache
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CORSCacheEntry {
|
||||
pub struct CorsCacheEntry {
|
||||
pub origin: Origin,
|
||||
pub url: Url,
|
||||
pub max_age: u32,
|
||||
|
@ -51,10 +51,10 @@ pub struct CORSCacheEntry {
|
|||
created: Timespec
|
||||
}
|
||||
|
||||
impl CORSCacheEntry {
|
||||
impl CorsCacheEntry {
|
||||
fn new(origin: Origin, url: Url, max_age: u32, credentials: bool,
|
||||
header_or_method: HeaderOrMethod) -> CORSCacheEntry {
|
||||
CORSCacheEntry {
|
||||
header_or_method: HeaderOrMethod) -> CorsCacheEntry {
|
||||
CorsCacheEntry {
|
||||
origin: origin,
|
||||
url: url,
|
||||
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.url == cors_req.current_url() &&
|
||||
(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
|
||||
#[derive(Clone)]
|
||||
pub struct CORSCache(Vec<CORSCacheEntry>);
|
||||
pub struct CorsCache(Vec<CorsCacheEntry>);
|
||||
|
||||
impl CORSCache {
|
||||
pub fn new() -> CORSCache {
|
||||
CORSCache(vec![])
|
||||
impl CorsCache {
|
||||
pub fn new() -> CorsCache {
|
||||
CorsCache(vec![])
|
||||
}
|
||||
|
||||
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.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,
|
||||
method: Method) -> Option<&'a mut CORSCacheEntry> {
|
||||
// we can take the method from CORSRequest itself
|
||||
method: Method) -> Option<&'a mut CorsCacheEntry> {
|
||||
// we can take the method from CorSRequest itself
|
||||
self.cleanup();
|
||||
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)
|
||||
pub fn clear(&mut self, request: &Request) {
|
||||
let CORSCache(buf) = self.clone();
|
||||
let new_buf: Vec<CORSCacheEntry> =
|
||||
let CorsCache(buf) = self.clone();
|
||||
let new_buf: Vec<CorsCacheEntry> =
|
||||
buf.into_iter().filter(|e| e.origin == *request.origin.borrow() &&
|
||||
request.current_url() == e.url).collect();
|
||||
*self = CORSCache(new_buf);
|
||||
*self = CorsCache(new_buf);
|
||||
}
|
||||
|
||||
/// Remove old entries
|
||||
pub fn cleanup(&mut self) {
|
||||
let CORSCache(buf) = self.clone();
|
||||
let CorsCache(buf) = self.clone();
|
||||
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)
|
||||
.collect();
|
||||
*self = CORSCache(new_buf);
|
||||
*self = CorsCache(new_buf);
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
Some(_) => true,
|
||||
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,
|
||||
HeaderOrMethod::HeaderData(header_name.to_owned())));
|
||||
false
|
||||
|
@ -149,7 +149,7 @@ impl CORSCache {
|
|||
match self.find_entry_by_method(&request, method.clone()).map(|e| e.max_age = new_max_age) {
|
||||
Some(_) => true,
|
||||
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,
|
||||
HeaderOrMethod::MethodData(method)));
|
||||
false
|
||||
|
@ -158,7 +158,7 @@ impl CORSCache {
|
|||
}
|
||||
|
||||
/// Insert an entry
|
||||
pub fn insert(&mut self, entry: CORSCacheEntry) {
|
||||
pub fn insert(&mut self, entry: CorsCacheEntry) {
|
||||
self.cleanup();
|
||||
self.0.push(entry);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use blob_loader::load_blob_sync;
|
|||
use connector::create_http_connector;
|
||||
use data_loader::decode;
|
||||
use devtools_traits::DevtoolsControlMsg;
|
||||
use fetch::cors_cache::CORSCache;
|
||||
use fetch::cors_cache::CorsCache;
|
||||
use filemanager_thread::{FileManager, UIProvider};
|
||||
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};
|
||||
|
@ -65,11 +65,11 @@ pub fn fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
target: &mut Target,
|
||||
context: &FetchContext<UI>)
|
||||
-> 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>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
target: &mut Target,
|
||||
context: &FetchContext<UI>)
|
||||
-> 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)
|
||||
fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
cors_flag: bool,
|
||||
recursive_flag: bool,
|
||||
target: &mut Target,
|
||||
|
@ -213,7 +213,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
} else if request.mode == RequestMode::SameOrigin {
|
||||
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);
|
||||
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 &&
|
||||
(!is_simple_method(&request.method.borrow()) ||
|
||||
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);
|
||||
let response = http_fetch(request.clone(), cache, true, true, false,
|
||||
target, done_chan, context);
|
||||
|
@ -234,7 +234,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
response
|
||||
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ fn main_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
let response = if response.response_type == ResponseType::Default {
|
||||
let response_type = match request.response_tainting.get() {
|
||||
ResponseTainting::Basic => ResponseType::Basic,
|
||||
ResponseTainting::CORSTainting => ResponseType::CORS,
|
||||
ResponseTainting::CorsTainting => ResponseType::Cors,
|
||||
ResponseTainting::Opaque => ResponseType::Opaque,
|
||||
};
|
||||
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)
|
||||
fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
target: &mut Target,
|
||||
done_chan: &mut DoneChannel,
|
||||
context: &FetchContext<UI>)
|
||||
|
@ -499,7 +499,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
|
||||
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
||||
fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
cors_flag: bool,
|
||||
cors_preflight_flag: bool,
|
||||
authentication_fetch_flag: bool,
|
||||
|
@ -526,7 +526,7 @@ fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
|
||||
// Substep 3
|
||||
if (res.response_type == ResponseType::Opaque &&
|
||||
request.mode != RequestMode::NoCORS) ||
|
||||
request.mode != RequestMode::NoCors) ||
|
||||
(res.response_type == ResponseType::OpaqueRedirect &&
|
||||
request.redirect_mode.get() != RedirectMode::Manual) ||
|
||||
(res.url_list.borrow().len() > 1 &&
|
||||
|
@ -674,7 +674,7 @@ fn http_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
|
||||
/// [HTTP redirect fetch](https://fetch.spec.whatwg.org#http-redirect-fetch)
|
||||
fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
response: Response,
|
||||
cors_flag: bool,
|
||||
target: &mut Target,
|
||||
|
@ -720,7 +720,7 @@ fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
};
|
||||
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()));
|
||||
}
|
||||
|
||||
|
@ -1166,7 +1166,7 @@ fn http_network_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
|||
|
||||
/// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch)
|
||||
fn cors_preflight_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||
cache: &mut CORSCache,
|
||||
cache: &mut CorsCache,
|
||||
context: &FetchContext<UI>)
|
||||
-> Response {
|
||||
// Step 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue