diff --git a/src/components/net/http_loader.rs b/src/components/net/http_loader.rs index b1f6f6f8c78..55467fa573d 100644 --- a/src/components/net/http_loader.rs +++ b/src/components/net/http_loader.rs @@ -106,6 +106,20 @@ fn load(load_data: LoadData, start_chan: Sender) { if 3 == (response.status.code() / 100) { match response.headers.location { Some(new_url) => { + // CORS (http://fetch.spec.whatwg.org/#http-fetch, status section, point 9, 10) + match load_data.cors { + Some(ref c) => { + if c.preflight { + // The preflight lied + send_error(url, "Preflight fetch inconsistent with main fetch".to_string(), start_chan); + return; + } else { + // XXXManishearth There are some CORS-related steps here, + // but they don't seem necessary until credentials are implemented + } + } + _ => {} + } info!("redirecting to {:s}", new_url.serialize()); url = new_url; continue; diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 15ede7b28e3..8dd2f5d37db 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -32,7 +32,8 @@ pub struct LoadData { pub url: Url, pub method: Method, pub headers: RequestHeaderCollection, - pub data: Option> + pub data: Option>, + pub cors: Option } impl LoadData { @@ -41,11 +42,20 @@ impl LoadData { url: url, method: Get, headers: RequestHeaderCollection::new(), - data: None + data: None, + cors: None } } } +#[deriving(Clone)] +pub struct ResourceCORSData { + /// CORS Preflight flag + pub preflight: bool, + /// Origin of CORS Request + pub origin: Url +} + /// Metadata about a loaded resource, such as is obtained from HTTP headers. pub struct Metadata { /// Final URL after redirects. diff --git a/src/components/script/cors.rs b/src/components/script/cors.rs new file mode 100644 index 00000000000..8cfca743808 --- /dev/null +++ b/src/components/script/cors.rs @@ -0,0 +1,418 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! A partial implementation of CORS +//! For now this library is XHR-specific. +//! For stuff involving ,