servo: Merge #5091 - Remove AccessControl header implementations in favor of hyper’s (from dhneio:5090); r=jdm
authordhneio <dhneio@eml.cc>
Fri, 27 Feb 2015 09:48:58 -0700
changeset 335834 e66493fa35a85159fa81ab9fb9bb9c9697d97f8d
parent 335833 5fe2d6e4e3bfaf429269ad3a931670592ca8042e
child 335835 dd8301221add6c72ab40c5012df8ae6ebd6d9e13
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #5091 - Remove AccessControl header implementations in favor of hyper’s (from dhneio:5090); r=jdm We no longer need these header implementations as they are included in hyper. Fixes #5090. Source-Repo: https://github.com/servo/servo Source-Revision: 60ce6c3b0fa7bd4199976a2b7e18f14df99bc511
servo/components/script/cors.rs
--- a/servo/components/script/cors.rs
+++ b/servo/components/script/cors.rs
@@ -5,23 +5,23 @@
 //! A partial implementation of CORS
 //! For now this library is XHR-specific.
 //! For stuff involving `<img>`, `<iframe>`, `<form>`, etc please check what
 //! the request mode should be and compare with the fetch spec
 //! This library will eventually become the core of the Fetch crate
 //! with CORSRequest being expanded into FetchRequest (etc)
 
 use std::ascii::AsciiExt;
-use std::fmt::{self, Display};
-use std::str::from_utf8;
 use time;
 use time::{now, Timespec};
 
-use hyper::header::{Headers, Header, HeaderFormat, HeaderView};
-use hyper::header::parsing as header_parsing;
+use hyper::header::{AccessControlRequestMethod, AccessControlAllowMethods};
+use hyper::header::{AccessControlMaxAge, AccessControlAllowOrigin};
+use hyper::header::{AccessControlRequestHeaders, AccessControlAllowHeaders};
+use hyper::header::{Headers, HeaderView};
 use hyper::client::Request;
 use hyper::mime::{Mime, TopLevel, SubLevel};
 use hyper::header::{ContentType, Host};
 use hyper::method::Method;
 use hyper::status::StatusClass::Success;
 
 use url::{SchemeData, Url};
 
@@ -377,160 +377,16 @@ fn is_simple_header(h: &HeaderView) -> b
 
 fn is_simple_method(m: &Method) -> bool {
     match *m {
         Method::Get | Method::Head | Method::Post => true,
         _ => false
     }
 }
 
-//XXX(seanmonstar): worth uplifting to Hyper?
-#[derive(Clone)]
-struct AccessControlRequestMethod(pub Method);
-
-impl Header for AccessControlRequestMethod {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Request-Method"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlRequestMethod> {
-        header_parsing::from_one_raw_str(raw).map(AccessControlRequestMethod)
-    }
-}
-
-impl HeaderFormat for AccessControlRequestMethod {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let AccessControlRequestMethod(ref method) = *self;
-        <_ as Display>::fmt(method, f)
-    }
-}
-
-#[derive(Clone)]
-struct AccessControlRequestHeaders(pub Vec<String>);
-
-impl Header for AccessControlRequestHeaders {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Request-Headers"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlRequestHeaders> {
-        header_parsing::from_comma_delimited(raw).map(AccessControlRequestHeaders)
-    }
-}
-
-impl HeaderFormat for AccessControlRequestHeaders {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let AccessControlRequestHeaders(ref parts) = *self;
-        header_parsing::fmt_comma_delimited(f, parts.as_slice())
-    }
-}
-
-#[derive(Clone)]
-struct AccessControlAllowMethods(pub Vec<Method>);
-
-impl Header for AccessControlAllowMethods {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Allow-Methods"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowMethods> {
-        header_parsing::from_comma_delimited(raw).map(AccessControlAllowMethods)
-    }
-}
-
-impl HeaderFormat for AccessControlAllowMethods {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let AccessControlAllowMethods(ref parts) = *self;
-        header_parsing::fmt_comma_delimited(f, parts.as_slice())
-    }
-}
-
-#[derive(Clone)]
-struct AccessControlAllowHeaders(pub Vec<String>);
-
-impl Header for AccessControlAllowHeaders {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Allow-Headers"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowHeaders> {
-        header_parsing::from_comma_delimited(raw).map(AccessControlAllowHeaders)
-    }
-}
-
-impl HeaderFormat for AccessControlAllowHeaders {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let AccessControlAllowHeaders(ref parts) = *self;
-        header_parsing::fmt_comma_delimited(f, parts.as_slice())
-    }
-}
-
-#[derive(Clone)]
-enum AccessControlAllowOrigin {
-    AllowStar,
-    AllowOrigin(Url),
-}
-
-
-impl Header for AccessControlAllowOrigin {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Allow-Origin"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
-        if raw.len() == 1 {
-            from_utf8(raw[0].as_slice()).ok().and_then(|s| {
-                if s == "*" {
-                    Some(AccessControlAllowOrigin::AllowStar)
-                } else {
-                    Url::parse(s).ok().map(|url| AccessControlAllowOrigin::AllowOrigin(url))
-                }
-            })
-        } else {
-            None
-        }
-    }
-}
-
-impl HeaderFormat for AccessControlAllowOrigin {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match *self {
-            AccessControlAllowOrigin::AllowStar => <_ as Display>::fmt("*", f),
-            AccessControlAllowOrigin::AllowOrigin(ref url) => <_ as Display>::fmt(url, f)
-        }
-    }
-}
-
-#[derive(Clone)]
-struct AccessControlMaxAge(pub u32);
-
-impl Header for AccessControlMaxAge {
-    #[inline]
-    fn header_name() -> &'static str {
-        "Access-Control-Max-Age"
-    }
-
-    fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlMaxAge> {
-        header_parsing::from_one_raw_str(raw).map(AccessControlMaxAge)
-    }
-}
-
-impl HeaderFormat for AccessControlMaxAge {
-    fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let AccessControlMaxAge(ref num) = *self;
-        <_ as Display>::fmt(num, f)
-    }
-}
-
-
 /// Perform a CORS check on a header list and CORS request
 /// http://fetch.spec.whatwg.org/#cors-check
 pub fn allow_cross_origin_request(req: &CORSRequest, headers: &Headers) -> bool {
     //FIXME(seanmonstar): use req.headers.get::<AccessControlAllowOrigin>()
     match headers.get() {
         Some(&AccessControlAllowOrigin::AllowStar) => true, // Not always true, depends on credentials mode
         Some(&AccessControlAllowOrigin::AllowOrigin(ref url)) =>
             url.scheme == req.origin.scheme &&