refactor(headers): Add tests and docs to CORS headers
This commit is contained in:
@@ -7,7 +7,17 @@ header! {
|
||||
#[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."]
|
||||
#[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>)*
|
||||
|
||||
test_access_control_allow_headers {}
|
||||
|
||||
test_access_control_allow_headers {
|
||||
test_header!(test1, vec![b"accept-language, date"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,17 @@ header! {
|
||||
#[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."]
|
||||
#[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)*
|
||||
|
||||
test_access_control_allow_methods {}
|
||||
test_access_control_allow_methods {
|
||||
test_header!(test1, vec![b"PUT, DELETE, XMODIFY"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
use std::fmt::{self};
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
use url::Url;
|
||||
use 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
|
||||
/// > can be shared based by returning the value of the Origin request header,
|
||||
/// > "*", or "null" in the response.
|
||||
/// The `Access-Control-Allow-Origin` header indicates whether a resource
|
||||
/// can be shared based by returning the value of the Origin request header,
|
||||
/// "*", 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)]
|
||||
pub enum AccessControlAllowOrigin {
|
||||
/// Allow all origins
|
||||
|
||||
@@ -4,7 +4,17 @@ 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."]
|
||||
#[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]
|
||||
|
||||
test_access_control_max_age {}
|
||||
test_access_control_max_age {
|
||||
test_header!(test1, vec![b"531"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,17 @@ header! {
|
||||
#[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."]
|
||||
#[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>)*
|
||||
|
||||
test_access_control_request_headers {}
|
||||
test_access_control_request_headers {
|
||||
test_header!(test1, vec![b"accept-language, date"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,16 @@ 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."]
|
||||
#[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]
|
||||
|
||||
test_access_control_request_method {}
|
||||
test_access_control_request_method {
|
||||
test_header!(test1, vec![b"GET"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user