diff --git a/src/header/common/access_control/allow_headers.rs b/src/header/common/access_control/allow_headers.rs deleted file mode 100644 index b61e59df77..0000000000 --- a/src/header/common/access_control/allow_headers.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::fmt::{self}; - -use header; - -/// The `Access-Control-Allow-Headers` response header, -/// part of [CORS](http://www.w3.org/TR/cors/). -/// -/// > The `Access-Control-Allow-Headers` header indicates, as part of the -/// > response to a preflight request, which header field names can be used -/// > during the actual request. -/// -/// Spec: www.w3.org/TR/cors/#access-control-allow-headers-response-header -#[derive(Clone, PartialEq, Debug)] -pub struct AccessControlAllowHeaders(pub Vec); - -impl header::Header for AccessControlAllowHeaders { - #[inline] - fn header_name() -> &'static str { - "Access-Control-Allow-Headers" - } - - fn parse_header(raw: &[Vec]) -> Option { - header::parsing::from_comma_delimited(raw).map(AccessControlAllowHeaders) - } -} - -impl header::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_ref()) - } -} diff --git a/src/header/common/access_control/allow_methods.rs b/src/header/common/access_control/allow_methods.rs deleted file mode 100644 index be85ab5205..0000000000 --- a/src/header/common/access_control/allow_methods.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::fmt::{self}; - -use header; -use method; - -/// The `Access-Control-Allow-Methods` response header, -/// part of [CORS](http://www.w3.org/TR/cors/). -/// -/// > The `Access-Control-Allow-Methods` header indicates, as part of the -/// > response to a preflight request, which methods can be used during the -/// > actual request. -/// -/// Spec: www.w3.org/TR/cors/#access-control-allow-methods-response-header -#[derive(Clone, PartialEq, Debug)] -pub struct AccessControlAllowMethods(pub Vec); - -impl header::Header for AccessControlAllowMethods { - #[inline] - fn header_name() -> &'static str { - "Access-Control-Allow-Methods" - } - - fn parse_header(raw: &[Vec]) -> Option { - header::parsing::from_comma_delimited(raw).map(AccessControlAllowMethods) - } -} - -impl header::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_ref()) - } -} diff --git a/src/header/common/access_control/max_age.rs b/src/header/common/access_control/max_age.rs deleted file mode 100644 index 69e509ca70..0000000000 --- a/src/header/common/access_control/max_age.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::fmt; - -use header; - -/// The `Access-Control-Max-Age` response header, -/// part of [CORS](http://www.w3.org/TR/cors/). -/// -/// > The `Access-Control-Max-Age` header indicates how long the results of a -/// > preflight request can be cached in a preflight result cache. -/// -/// Spec: www.w3.org/TR/cors/#access-control-max-age-response-header -#[derive(Clone, Copy, PartialEq, Debug)] -pub struct AccessControlMaxAge(pub u32); - -impl header::Header for AccessControlMaxAge { - #[inline] - fn header_name() -> &'static str { - "Access-Control-Max-Age" - } - - fn parse_header(raw: &[Vec]) -> Option { - header::parsing::from_one_raw_str(raw).map(AccessControlMaxAge) - } -} - -impl header::HeaderFormat for AccessControlMaxAge { - fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { - let AccessControlMaxAge(ref num) = *self; - write!(f, "{}", num) - } -} diff --git a/src/header/common/access_control/mod.rs b/src/header/common/access_control/mod.rs deleted file mode 100644 index 526e6f5526..0000000000 --- a/src/header/common/access_control/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -pub use self::allow_headers::AccessControlAllowHeaders; -pub use self::allow_methods::AccessControlAllowMethods; -pub use self::allow_origin::AccessControlAllowOrigin; -pub use self::max_age::AccessControlMaxAge; -pub use self::request_headers::AccessControlRequestHeaders; -pub use self::request_method::AccessControlRequestMethod; - -mod allow_headers; -mod allow_methods; -mod allow_origin; -mod max_age; -mod request_headers; -mod request_method; diff --git a/src/header/common/access_control/request_headers.rs b/src/header/common/access_control/request_headers.rs deleted file mode 100644 index e90ea17371..0000000000 --- a/src/header/common/access_control/request_headers.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::fmt::{self}; - -use header; - -/// The `Access-Control-Request-Headers` request header, -/// part of [CORS](http://www.w3.org/TR/cors/). -/// -/// > The `Access-Control-Request-Headers` header indicates which headers will -/// > be used in the actual request as part of the preflight request. -/// -/// Spec: www.w3.org/TR/cors/#access-control-request-headers-request-header -#[derive(Clone, PartialEq, Debug)] -pub struct AccessControlRequestHeaders(pub Vec); - -impl header::Header for AccessControlRequestHeaders { - #[inline] - fn header_name() -> &'static str { - "Access-Control-Request-Headers" - } - - fn parse_header(raw: &[Vec]) -> Option { - header::parsing::from_comma_delimited(raw).map(AccessControlRequestHeaders) - } -} - -impl header::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_ref()) - } -} diff --git a/src/header/common/access_control/request_method.rs b/src/header/common/access_control/request_method.rs deleted file mode 100644 index d679a39047..0000000000 --- a/src/header/common/access_control/request_method.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::fmt; - -use header; -use method::Method; - -/// The `Access-Control-Request-Method` request header, -/// part of [CORS](http://www.w3.org/TR/cors/). -/// -/// > The `Access-Control-Request-Method` header indicates which method will be -/// > used in the actual request as part of the preflight request. -/// -/// Spec: www.w3.org/TR/cors/#access-control-request-method-request-header -#[derive(Clone, PartialEq, Debug)] -pub struct AccessControlRequestMethod(pub Method); - -impl header::Header for AccessControlRequestMethod { - #[inline] - fn header_name() -> &'static str { - "Access-Control-Request-Method" - } - - fn parse_header(raw: &[Vec]) -> Option { - header::parsing::from_one_raw_str(raw).map(AccessControlRequestMethod) - } -} - -impl header::HeaderFormat for AccessControlRequestMethod { - fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { - let AccessControlRequestMethod(ref method) = *self; - write!(f, "{}", method) - } -} diff --git a/src/header/common/access_control_allow_headers.rs b/src/header/common/access_control_allow_headers.rs new file mode 100644 index 0000000000..da5dea0830 --- /dev/null +++ b/src/header/common/access_control_allow_headers.rs @@ -0,0 +1,11 @@ +use unicase::UniCase; + +header! { + #[doc="`Access-Control-Allow-Headers` header, part of"] + #[doc="[CORS](www.w3.org/TR/cors/#access-control-allow-headers-response-header)"] + #[doc=""] + #[doc="The `Access-Control-Allow-Headers` header indicates, as part of the"] + #[doc="response to a preflight request, which header field names can be used"] + #[doc="during the actual request."] + (AccessControlAllowHeaders, "Access-Control-Allow-Headers") => (UniCase)* +} \ No newline at end of file diff --git a/src/header/common/access_control_allow_methods.rs b/src/header/common/access_control_allow_methods.rs new file mode 100644 index 0000000000..8d12de3849 --- /dev/null +++ b/src/header/common/access_control_allow_methods.rs @@ -0,0 +1,11 @@ +use method::Method; + +header! { + #[doc="`Access-Control-Allow-Methods` header, part of"] + #[doc="[CORS](www.w3.org/TR/cors/#access-control-allow-methods-response-header)"] + #[doc=""] + #[doc="The `Access-Control-Allow-Methods` header indicates, as part of the"] + #[doc="response to a preflight request, which methods can be used during the"] + #[doc="actual request."] + (AccessControlAllowMethods, "Access-Control-Allow-Methods") => (Method)* +} diff --git a/src/header/common/access_control/allow_origin.rs b/src/header/common/access_control_allow_origin.rs similarity index 76% rename from src/header/common/access_control/allow_origin.rs rename to src/header/common/access_control_allow_origin.rs index b7bde04d0e..3092045079 100644 --- a/src/header/common/access_control/allow_origin.rs +++ b/src/header/common/access_control_allow_origin.rs @@ -1,8 +1,7 @@ -extern crate url; - use std::fmt::{self}; use std::str; +use url::Url; use header; /// The `Access-Control-Allow-Origin` response header, @@ -16,13 +15,12 @@ use header; #[derive(Clone, PartialEq, Debug)] pub enum AccessControlAllowOrigin { /// Allow all origins - AllowStar, + Any, /// Allow one particular origin - AllowOrigin(url::Url), + Value(Url), } impl header::Header for AccessControlAllowOrigin { - #[inline] fn header_name() -> &'static str { "Access-Control-Allow-Origin" } @@ -32,10 +30,10 @@ impl header::Header for AccessControlAllowOrigin { match str::from_utf8(unsafe { &raw.get_unchecked(0)[..] }) { Ok(s) => { if s == "*" { - Some(AccessControlAllowOrigin::AllowStar) + Some(AccessControlAllowOrigin::Any) } else { - url::Url::parse(s).ok().map( - |url| AccessControlAllowOrigin::AllowOrigin(url)) + Url::parse(s).ok().map( + |url| AccessControlAllowOrigin::Value(url)) } }, _ => return None, @@ -49,8 +47,8 @@ impl header::Header for AccessControlAllowOrigin { impl header::HeaderFormat for AccessControlAllowOrigin { fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - AccessControlAllowOrigin::AllowStar => write!(f, "*"), - AccessControlAllowOrigin::AllowOrigin(ref url) => + AccessControlAllowOrigin::Any => write!(f, "*"), + AccessControlAllowOrigin::Value(ref url) => write!(f, "{}", url) } } diff --git a/src/header/common/access_control_max_age.rs b/src/header/common/access_control_max_age.rs new file mode 100644 index 0000000000..b5a9aec235 --- /dev/null +++ b/src/header/common/access_control_max_age.rs @@ -0,0 +1,8 @@ +header! { + #[doc="`Access-Control-Max-Age` header, part of"] + #[doc="[CORS](www.w3.org/TR/cors/#access-control-max-age-response-header)"] + #[doc=""] + #[doc="The `Access-Control-Max-Age` header indicates how long the results of a"] + #[doc="preflight request can be cached in a preflight result cache."] + (AccessControlMaxAge, "Access-Control-Max-Age") => [u32] +} \ No newline at end of file diff --git a/src/header/common/access_control_request_headers.rs b/src/header/common/access_control_request_headers.rs new file mode 100644 index 0000000000..79f57d2128 --- /dev/null +++ b/src/header/common/access_control_request_headers.rs @@ -0,0 +1,11 @@ +use unicase::UniCase; + +header! { + #[doc="`Access-Control-Request-Headers` header, part of"] + #[doc="[CORS](www.w3.org/TR/cors/#access-control-request-headers-request-header)"] + #[doc=""] + #[doc="The `Access-Control-Request-Headers` header indicates which headers will"] + #[doc="be used in the actual request as part of the preflight request."] + #[doc="during the actual request."] + (AccessControlRequestHeaders, "Access-Control-Request-Headers") => (UniCase)* +} diff --git a/src/header/common/access_control_request_method.rs b/src/header/common/access_control_request_method.rs new file mode 100644 index 0000000000..5706dfee24 --- /dev/null +++ b/src/header/common/access_control_request_method.rs @@ -0,0 +1,10 @@ +use method::Method; + +header! { + #[doc="`Access-Control-Request-Method` header, part of"] + #[doc="[CORS](www.w3.org/TR/cors/#access-control-request-method-request-header)"] + #[doc=""] + #[doc="The `Access-Control-Request-Method` header indicates which method will be"] + #[doc="used in the actual request as part of the preflight request."] + (AccessControlRequestMethod, "Access-Control-Request-Method") => [Method] +} \ No newline at end of file diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index cadbd1b0e4..8a882a9116 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -6,8 +6,13 @@ //! strongly-typed theme, the [mime](http://seanmonstar.github.io/mime.rs) crate //! is used, such as `ContentType(pub Mime)`. -pub use self::access_control::*; pub use self::accept::Accept; +pub use self::access_control_allow_headers::AccessControlAllowHeaders; +pub use self::access_control_allow_methods::AccessControlAllowMethods; +pub use self::access_control_allow_origin::AccessControlAllowOrigin; +pub use self::access_control_max_age::AccessControlMaxAge; +pub use self::access_control_request_headers::AccessControlRequestHeaders; +pub use self::access_control_request_method::AccessControlRequestMethod; pub use self::accept_charset::AcceptCharset; pub use self::accept_encoding::AcceptEncoding; pub use self::accept_language::AcceptLanguage; @@ -216,8 +221,13 @@ macro_rules! header { }; } -mod access_control; mod accept; +mod access_control_allow_headers; +mod access_control_allow_methods; +mod access_control_allow_origin; +mod access_control_max_age; +mod access_control_request_headers; +mod access_control_request_method; mod accept_charset; mod accept_encoding; mod accept_language;