refactor(headers): Add tests and docs to CORS headers

This commit is contained in:
Pyfisch
2015-04-28 09:32:48 +02:00
parent f9d75e4dd3
commit e993f4b544
6 changed files with 66 additions and 12 deletions

View File

@@ -7,7 +7,17 @@ header! {
#[doc="The `Access-Control-Allow-Headers` header indicates, as part of the"] #[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="response to a preflight request, which header field names can be used"]
#[doc="during the actual request."] #[doc="during the actual request."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Access-Control-Allow-Headers: \"Access-Control-Allow-Headers\" \":\" #field-name"]
#[doc="```"]
#[doc=""]
#[doc="# Example values"]
#[doc="* `accept-language, date`"]
(AccessControlAllowHeaders, "Access-Control-Allow-Headers") => (UniCase<String>)* (AccessControlAllowHeaders, "Access-Control-Allow-Headers") => (UniCase<String>)*
test_access_control_allow_headers {} test_access_control_allow_headers {
test_header!(test1, vec![b"accept-language, date"]);
}
} }

View File

@@ -7,7 +7,17 @@ header! {
#[doc="The `Access-Control-Allow-Methods` header indicates, as part of the"] #[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="response to a preflight request, which methods can be used during the"]
#[doc="actual request."] #[doc="actual request."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Access-Control-Allow-Methods: \"Access-Control-Allow-Methods\" \":\" #Method"]
#[doc="```"]
#[doc=""]
#[doc="# Example values"]
#[doc="* `PUT, DELETE, XMODIFY`"]
(AccessControlAllowMethods, "Access-Control-Allow-Methods") => (Method)* (AccessControlAllowMethods, "Access-Control-Allow-Methods") => (Method)*
test_access_control_allow_methods {} test_access_control_allow_methods {
test_header!(test1, vec![b"PUT, DELETE, XMODIFY"]);
}
} }

View File

@@ -1,17 +1,22 @@
use std::fmt::{self}; use std::fmt;
use std::str; use std::str;
use url::Url; use url::Url;
use header; use header;
/// The `Access-Control-Allow-Origin` response header, /// The `Access-Control-Allow-Origin` response header,
/// part of [CORS](http://www.w3.org/TR/cors/). /// part of [CORS](www.w3.org/TR/cors/#access-control-allow-origin-response-header)
/// ///
/// > The `Access-Control-Allow-Origin` header indicates whether a resource /// The `Access-Control-Allow-Origin` header indicates whether a resource
/// > can be shared based by returning the value of the Origin request header, /// can be shared based by returning the value of the Origin request header,
/// > "*", or "null" in the response. /// "*", or "null" in the response.
/// ///
/// Spec: www.w3.org/TR/cors/#access-control-allow-origin-response-header /// # ABNF
/// ```plain
/// Access-Control-Allow-Origin = "Access-Control-Allow-Origin" ":" origin-list-or-null | "*"
/// ```
// FIXME: The documentation says differently (missing "null" value, "*" not used in practice,
// orgin list no list but single value)
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
pub enum AccessControlAllowOrigin { pub enum AccessControlAllowOrigin {
/// Allow all origins /// Allow all origins

View File

@@ -4,7 +4,17 @@ header! {
#[doc=""] #[doc=""]
#[doc="The `Access-Control-Max-Age` header indicates how long the results of a"] #[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."] #[doc="preflight request can be cached in a preflight result cache."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Access-Control-Max-Age = \"Access-Control-Max-Age\" \":\" delta-seconds"]
#[doc="```"]
#[doc=""]
#[doc="# Example values"]
#[doc="* `531`"]
(AccessControlMaxAge, "Access-Control-Max-Age") => [u32] (AccessControlMaxAge, "Access-Control-Max-Age") => [u32]
test_access_control_max_age {} test_access_control_max_age {
test_header!(test1, vec![b"531"]);
}
} }

View File

@@ -7,7 +7,17 @@ header! {
#[doc="The `Access-Control-Request-Headers` header indicates which headers will"] #[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="be used in the actual request as part of the preflight request."]
#[doc="during the actual request."] #[doc="during the actual request."]
#[doc=""]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Access-Control-Allow-Headers: \"Access-Control-Allow-Headers\" \":\" #field-name"]
#[doc="```"]
#[doc=""]
#[doc="# Example values"]
#[doc="* `accept-language, date`"]
(AccessControlRequestHeaders, "Access-Control-Request-Headers") => (UniCase<String>)* (AccessControlRequestHeaders, "Access-Control-Request-Headers") => (UniCase<String>)*
test_access_control_request_headers {} test_access_control_request_headers {
test_header!(test1, vec![b"accept-language, date"]);
}
} }

View File

@@ -6,7 +6,16 @@ header! {
#[doc=""] #[doc=""]
#[doc="The `Access-Control-Request-Method` header indicates which method will be"] #[doc="The `Access-Control-Request-Method` header indicates which method will be"]
#[doc="used in the actual request as part of the preflight request."] #[doc="used in the actual request as part of the preflight request."]
#[doc="# ABNF"]
#[doc="```plain"]
#[doc="Access-Control-Request-Method: \"Access-Control-Request-Method\" \":\" Method"]
#[doc="```"]
#[doc=""]
#[doc="# Example values"]
#[doc="* `GET`"]
(AccessControlRequestMethod, "Access-Control-Request-Method") => [Method] (AccessControlRequestMethod, "Access-Control-Request-Method") => [Method]
test_access_control_request_method {} test_access_control_request_method {
test_header!(test1, vec![b"GET"]);
}
} }