refactor(headers): export all headers and utils directly under header

Currently headers are exported at many places. For example you can access
`Transfer-Encoding` header at `header`, `header::common` and
`header::common::transfer_encoding`. Per discussion on IRC with
@seanmonstar and @reem, all contents of headers will be exposed at `header`
directly. Parsing utilities will be exposed at `header::parsing`. Header
macros can now be used from other crates.

This breaks much code using headers. It should use everything it needs
directly from `header::`, encodings are exposed at `header::Encoding::`,
connection options are exposed at `header::ConnectionOption`.
This commit is contained in:
Pyfisch
2015-01-20 13:04:42 +01:00
parent 7a5813b4b2
commit 8d0e5bc302
37 changed files with 223 additions and 272 deletions

View File

@@ -1,10 +1,17 @@
use std::fmt::{self};
use header;
use header::shared;
#[derive(Clone)]
struct AccessControlAllowHeaders(pub Vec<String>);
/// 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, Show)]
pub struct AccessControlAllowHeaders(pub Vec<String>);
impl header::Header for AccessControlAllowHeaders {
#[inline]
@@ -13,13 +20,13 @@ impl header::Header for AccessControlAllowHeaders {
}
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowHeaders> {
shared::from_comma_delimited(raw).map(AccessControlAllowHeaders)
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;
shared::fmt_comma_delimited(f, parts.as_slice())
header::parsing::fmt_comma_delimited(f, parts.as_slice())
}
}

View File

@@ -1,11 +1,18 @@
use std::fmt::{self};
use header;
use header::shared;
use method;
#[derive(Clone)]
struct AccessControlAllowMethods(pub Vec<method::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, Show)]
pub struct AccessControlAllowMethods(pub Vec<method::Method>);
impl header::Header for AccessControlAllowMethods {
#[inline]
@@ -14,13 +21,13 @@ impl header::Header for AccessControlAllowMethods {
}
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowMethods> {
shared::from_comma_delimited(raw).map(AccessControlAllowMethods)
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;
shared::fmt_comma_delimited(f, parts.as_slice())
header::parsing::fmt_comma_delimited(f, parts.as_slice())
}
}

View File

@@ -5,9 +5,19 @@ use std::str;
use header;
#[derive(Clone)]
enum AccessControlAllowOrigin {
/// The `Access-Control-Allow-Origin` response header,
/// part of [CORS](http://www.w3.org/TR/cors/).
///
/// > 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
#[derive(Clone, PartialEq, Show)]
pub enum AccessControlAllowOrigin {
/// Allow all origins
AllowStar,
/// Allow one particular origin
AllowOrigin(url::Url),
}

View File

@@ -1,10 +1,16 @@
use std::fmt;
use header;
use header::shared;
#[derive(Clone)]
struct AccessControlMaxAge(pub u32);
/// 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, Show)]
pub struct AccessControlMaxAge(pub u32);
impl header::Header for AccessControlMaxAge {
#[inline]
@@ -13,7 +19,7 @@ impl header::Header for AccessControlMaxAge {
}
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlMaxAge> {
shared::from_one_raw_str(raw).map(AccessControlMaxAge)
header::parsing::from_one_raw_str(raw).map(AccessControlMaxAge)
}
}

View File

@@ -1,17 +1,13 @@
/// Exposes the AccessControlAllowHeaders header
pub mod allow_headers;
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;
/// Exposes the AccessControlAllowMethods header
pub mod allow_methods;
/// Exposes the AccessControlAllowOrigin header
pub mod allow_origin;
/// Exposes the AccessControlMaxAge header
pub mod max_age;
/// Exposes the AccessControlRequestHeaders header
pub mod request_headers;
/// Exposes the AccessControlRequestMethod header
pub mod request_method;
mod allow_headers;
mod allow_methods;
mod allow_origin;
mod max_age;
mod request_headers;
mod request_method;

View File

@@ -1,10 +1,16 @@
use std::fmt::{self};
use header;
use header::shared;
#[derive(Clone)]
struct AccessControlRequestHeaders(pub Vec<String>);
/// 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, Show)]
pub struct AccessControlRequestHeaders(pub Vec<String>);
impl header::Header for AccessControlRequestHeaders {
#[inline]
@@ -13,13 +19,13 @@ impl header::Header for AccessControlRequestHeaders {
}
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlRequestHeaders> {
shared::from_comma_delimited(raw).map(AccessControlRequestHeaders)
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;
shared::fmt_comma_delimited(f, parts.as_slice())
header::parsing::fmt_comma_delimited(f, parts.as_slice())
}
}

View File

@@ -1,11 +1,17 @@
use std::fmt;
use header;
use header::shared;
use method::Method;
#[derive(Clone)]
struct AccessControlRequestMethod(pub 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, Show)]
pub struct AccessControlRequestMethod(pub Method);
impl header::Header for AccessControlRequestMethod {
#[inline]
@@ -14,7 +20,7 @@ impl header::Header for AccessControlRequestMethod {
}
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlRequestMethod> {
shared::from_one_raw_str(raw).map(AccessControlRequestMethod)
header::parsing::from_one_raw_str(raw).map(AccessControlRequestMethod)
}
}