Update rustc to revision 3dcd2157403163789aaf21a9ab3c4d30a7c6494d.

This commit is contained in:
Ms2ger 2014-12-17 10:42:52 +01:00 committed by Josh Matthews
parent b8900782b0
commit 466faac2a5
223 changed files with 4414 additions and 4105 deletions

View file

@ -23,7 +23,7 @@ use hyper::header::common::{ContentType, Host};
use hyper::method::{Method, Get, Head, Post, Options};
use hyper::status::Success;
use url::{RelativeSchemeData, Url};
use url::{SchemeData, Url};
#[deriving(Clone)]
pub struct CORSRequest {
@ -42,8 +42,8 @@ pub struct CORSRequest {
/// `same-origin` and `no CORS` modes are unnecessary for XHR.
#[deriving(PartialEq, Clone)]
pub enum RequestMode {
CORSMode, // CORS
ForcedPreflightMode // CORS-with-forced-preflight
CORS, // CORS
ForcedPreflight // CORS-with-forced-preflight
}
impl CORSRequest {
@ -60,7 +60,7 @@ impl CORSRequest {
// we can fetch a data URL normally. about:blank can also be fetched by XHR
"http" | "https" => {
let mut req = CORSRequest::new(referer, destination, mode, method, headers);
req.preflight_flag = !is_simple_method(&req.method) || mode == ForcedPreflightMode;
req.preflight_flag = !is_simple_method(&req.method) || mode == RequestMode::ForcedPreflight;
if req.headers.iter().all(|h| is_simple_header(&h)) {
req.preflight_flag = true;
}
@ -73,7 +73,7 @@ impl CORSRequest {
fn new(mut referer: Url, destination: Url, mode: RequestMode, method: Method,
headers: Headers) -> CORSRequest {
match referer.scheme_data {
RelativeSchemeData(ref mut data) => data.path = vec!(),
SchemeData::Relative(ref mut data) => data.path = vec!(),
_ => {}
};
referer.fragment = None;
@ -91,7 +91,7 @@ impl CORSRequest {
/// http://fetch.spec.whatwg.org/#concept-http-fetch
/// This method assumes that the CORS flag is set
/// This does not perform the full HTTP fetch, rather it handles part of the CORS filtering
/// if self.mode is ForcedPreflightMode, then the CORS-with-forced-preflight
/// if self.mode is ForcedPreflight, then the CORS-with-forced-preflight
/// fetch flag is set as well
pub fn http_fetch(&self) -> CORSResponse {
let response = CORSResponse::new();
@ -103,7 +103,7 @@ impl CORSRequest {
if self.preflight_flag &&
!cache.match_method(self, &self.method) &&
!self.headers.iter().all(|h| is_simple_header(&h) && cache.match_header(self, h.name())) {
if !is_simple_method(&self.method) || self.mode == ForcedPreflightMode {
if !is_simple_method(&self.method) || self.mode == RequestMode::ForcedPreflight {
return self.preflight_fetch();
// Everything after this is part of XHR::fetch()
// Expect the organization of code to improve once we have a fetch crate
@ -170,7 +170,7 @@ impl CORSRequest {
};
// Substep 4
let methods_substep4 = [self.method.clone()];
if methods.len() == 0 || preflight.mode == ForcedPreflightMode {
if methods.len() == 0 || preflight.mode == RequestMode::ForcedPreflight {
methods = methods_substep4.as_slice();
}
// Substep 5
@ -201,14 +201,14 @@ impl CORSRequest {
let cache_match = cache.match_method_and_update(self, m, max_age);
if !cache_match {
cache.insert(CORSCacheEntry::new(self.origin.clone(), self.destination.clone(),
max_age, false, MethodData(m.clone())));
max_age, false, HeaderOrMethod::MethodData(m.clone())));
}
}
for h in response.headers.iter() {
let cache_match = cache.match_header_and_update(self, h.name(), max_age);
if !cache_match {
cache.insert(CORSCacheEntry::new(self.origin.clone(), self.destination.clone(),
max_age, false, HeaderData(h.to_string())));
max_age, false, HeaderOrMethod::HeaderData(h.to_string())));
}
}
cors_response
@ -254,14 +254,14 @@ pub enum HeaderOrMethod {
impl HeaderOrMethod {
fn match_header(&self, header_name: &str) -> bool {
match *self {
HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name),
HeaderOrMethod::HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name),
_ => false
}
}
fn match_method(&self, method: &Method) -> bool {
match *self {
MethodData(ref m) => m == method,
HeaderOrMethod::MethodData(ref m) => m == method,
_ => false
}
}
@ -484,9 +484,9 @@ impl Header for AccessControlAllowOrigin {
if raw.len() == 1 {
from_utf8(raw[0].as_slice()).and_then(|s| {
if s == "*" {
Some(AllowStar)
Some(AccessControlAllowOrigin::AllowStar)
} else {
Url::parse(s).ok().map(|url| AllowOrigin(url))
Url::parse(s).ok().map(|url| AccessControlAllowOrigin::AllowOrigin(url))
}
})
} else {
@ -498,8 +498,8 @@ impl Header for AccessControlAllowOrigin {
impl HeaderFormat for AccessControlAllowOrigin {
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
AllowStar => "*".fmt(f),
AllowOrigin(ref url) => url.fmt(f)
AccessControlAllowOrigin::AllowStar => "*".fmt(f),
AccessControlAllowOrigin::AllowOrigin(ref url) => url.fmt(f)
}
}
}
@ -531,8 +531,8 @@ impl HeaderFormat for AccessControlMaxAge {
pub fn allow_cross_origin_request(req: &CORSRequest, headers: &Headers) -> bool {
//FIXME(seanmonstar): use req.headers.get::<AccessControlAllowOrigin>()
match headers.get() {
Some(&AllowStar) => true, // Not always true, depends on credentials mode
Some(&AllowOrigin(ref url)) =>
Some(&AccessControlAllowOrigin::AllowStar) => true, // Not always true, depends on credentials mode
Some(&AccessControlAllowOrigin::AllowOrigin(ref url)) =>
url.scheme == req.origin.scheme &&
url.host() == req.origin.host() &&
url.port() == req.origin.port(),