From eda194c451c59b9933e14a49b6b1f32bf4800986 Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Sat, 15 Jul 2017 11:56:00 +0800 Subject: [PATCH] "Turn on" serde --- src/headers.rs | 3 +++ src/lib.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/headers.rs b/src/headers.rs index 1cd71b0..2e3257b 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -12,7 +12,10 @@ use unicase::UniCase; use url; use url_serde; +/// A case insensitive header name pub(crate) type HeaderFieldName = UniCase; + +/// A set of case insensitive header names pub(crate) type HeaderFieldNamesSet = HashSet; /// A wrapped `url::Url` to allow for deserialization diff --git a/src/lib.rs b/src/lib.rs index 7361929..05b52d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -342,7 +342,7 @@ impl<'de> Deserialize<'de> for Method { /// /// [`Default`](https://doc.rust-lang.org/std/default/trait.Default.html) is implemented for this /// struct. The default for each field is described in the docuementation for the field. -#[derive(Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct Cors { /// Origins that are allowed to make requests. /// Will be verified against the `Origin` request header. @@ -360,7 +360,7 @@ pub struct Cors { /// Defaults to `All`. /// /// ``` - // #[serde(default)] + #[serde(default)] pub allowed_origins: AllOrSome>, /// The list of methods which the allowed origins are allowed to access for /// non-simple requests. @@ -369,7 +369,7 @@ pub struct Cors { /// [Resource Processing Model](https://www.w3.org/TR/cors/#resource-processing-model). /// /// Defaults to `[GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE]` - // #[serde(default = "Cors::default_allowed_methods")] + #[serde(default = "Cors::default_allowed_methods")] pub allowed_methods: HashSet, /// The list of header field names which can be used when this resource is accessed by allowed /// origins. @@ -381,7 +381,7 @@ pub struct Cors { /// [Resource Processing Model](https://www.w3.org/TR/cors/#resource-processing-model). /// /// Defaults to `All`. - // #[serde(default)] + #[serde(default)] pub allowed_headers: AllOrSome>, /// Allows users to make authenticated requests. /// If true, injects the `Access-Control-Allow-Credentials` header in responses. @@ -392,7 +392,7 @@ pub struct Cors { /// in an `Error::CredentialsWithWildcardOrigin` error during Rocket launch or runtime. /// /// Defaults to `false`. - // #[serde(default)] + #[serde(default)] pub allow_credentials: bool, /// The list of headers which are safe to expose to the API of a CORS API specification. /// This corresponds to the `Access-Control-Expose-Headers` responde header. @@ -401,13 +401,13 @@ pub struct Cors { /// [Resource Processing Model](https://www.w3.org/TR/cors/#resource-processing-model). /// /// This defaults to an empty set. - // #[serde(default)] + #[serde(default)] pub expose_headers: HashSet, /// The maximum time for which this CORS request maybe cached. This value is set as the /// `Access-Control-Max-Age` header. /// /// This defaults to `None` (unset). - // #[serde(default)] + #[serde(default)] pub max_age: Option, /// If true, and the `allowed_origins` parameter is `All`, a wildcard /// `Access-Control-Allow-Origin` response header is sent, rather than the request’s @@ -421,7 +421,7 @@ pub struct Cors { /// in an `Error::CredentialsWithWildcardOrigin` error during Rocket launch or runtime. /// /// Defaults to `false`. - // #[serde(default)] + #[serde(default)] pub send_wildcard: bool, }