Worked on Access-Control-* header family.
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
use std::fmt::{mod};
|
use std::fmt::{self};
|
||||||
|
|
||||||
use header;
|
use header;
|
||||||
use header::shared;
|
use header::shared;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
struct AccessControlAllowHeaders(pub Vec<String>);
|
struct AccessControlAllowHeaders(pub Vec<String>);
|
||||||
|
|
||||||
impl header::Header for AccessControlAllowHeaders {
|
impl header::Header for AccessControlAllowHeaders {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use std::fmt::{mod};
|
use std::fmt::{self};
|
||||||
|
|
||||||
use header;
|
use header;
|
||||||
use header::shared;
|
use header::shared;
|
||||||
|
use method;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
struct AccessControlAllowMethods(pub Vec<Method>);
|
struct AccessControlAllowMethods(pub Vec<method::Method>);
|
||||||
|
|
||||||
impl header::Header for AccessControlAllowMethods {
|
impl header::Header for AccessControlAllowMethods {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
use header::shared;
|
extern crate url;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
use std::fmt::{self};
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
use header;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
enum AccessControlAllowOrigin {
|
enum AccessControlAllowOrigin {
|
||||||
AllowStar,
|
AllowStar,
|
||||||
AllowOrigin(Url),
|
AllowOrigin(url::Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl header::Header for AccessControlAllowOrigin {
|
impl header::Header for AccessControlAllowOrigin {
|
||||||
@@ -14,15 +19,19 @@ impl header::Header for AccessControlAllowOrigin {
|
|||||||
|
|
||||||
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
|
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
|
||||||
if raw.len() == 1 {
|
if raw.len() == 1 {
|
||||||
from_utf8(raw[0].as_slice()).and_then(|s| {
|
match str::from_utf8(unsafe { raw[].get_unchecked(0)[] }) {
|
||||||
if s == "*" {
|
Ok(s) => {
|
||||||
Some(AllowStar)
|
if s == "*" {
|
||||||
} else {
|
Some(AccessControlAllowOrigin::AllowStar)
|
||||||
Url::parse(s).ok().map(|url| AllowOrigin(url))
|
} else {
|
||||||
}
|
url::Url::parse(s).ok().map(
|
||||||
})
|
|url| AccessControlAllowOrigin::AllowOrigin(url))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,8 +39,9 @@ impl header::Header for AccessControlAllowOrigin {
|
|||||||
impl header::HeaderFormat for AccessControlAllowOrigin {
|
impl header::HeaderFormat for AccessControlAllowOrigin {
|
||||||
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
AllowStar => "*".fmt(f),
|
AccessControlAllowOrigin::AllowStar => write!(f, "*"),
|
||||||
AllowOrigin(ref url) => url.fmt(f)
|
AccessControlAllowOrigin::AllowOrigin(ref url) =>
|
||||||
|
write!(f, "{}", url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
use header;
|
use header;
|
||||||
use header::shared;
|
use header::shared;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
struct AccessControlMaxAge(pub u32);
|
struct AccessControlMaxAge(pub u32);
|
||||||
|
|
||||||
impl header::Header for AccessControlMaxAge {
|
impl header::Header for AccessControlMaxAge {
|
||||||
@@ -18,6 +20,6 @@ impl header::Header for AccessControlMaxAge {
|
|||||||
impl header::HeaderFormat for AccessControlMaxAge {
|
impl header::HeaderFormat for AccessControlMaxAge {
|
||||||
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let AccessControlMaxAge(ref num) = *self;
|
let AccessControlMaxAge(ref num) = *self;
|
||||||
num.fmt(f)
|
write!(f, "{}", num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
|
/// Exposes the AccessControlAllowHeaders header
|
||||||
pub mod allow_headers;
|
pub mod allow_headers;
|
||||||
|
|
||||||
|
/// Exposes the AccessControlAllowMethods header
|
||||||
pub mod allow_methods;
|
pub mod allow_methods;
|
||||||
|
|
||||||
|
/// Exposes the AccessControlAllowOrigin header
|
||||||
pub mod allow_origin;
|
pub mod allow_origin;
|
||||||
|
|
||||||
|
/// Exposes the AccessControlMaxAge header
|
||||||
|
pub mod max_age;
|
||||||
|
|
||||||
|
/// Exposes the AccessControlRequestHeaders header
|
||||||
pub mod request_headers;
|
pub mod request_headers;
|
||||||
|
|
||||||
|
/// Exposes the AccessControlRequestMethod header
|
||||||
pub mod request_method;
|
pub mod request_method;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::fmt::{mod};
|
use std::fmt::{self};
|
||||||
|
|
||||||
use header;
|
use header;
|
||||||
use header::shared;
|
use header::shared;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
struct AccessControlRequestHeaders(pub Vec<String>);
|
struct AccessControlRequestHeaders(pub Vec<String>);
|
||||||
|
|
||||||
impl header::Header for AccessControlRequestHeaders {
|
impl header::Header for AccessControlRequestHeaders {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::fmt::{mod};
|
use std::fmt;
|
||||||
|
|
||||||
use header;
|
use header;
|
||||||
use header::shared;
|
use header::shared;
|
||||||
use method::Method;
|
use method::Method;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
struct AccessControlRequestMethod(pub Method);
|
struct AccessControlRequestMethod(pub Method);
|
||||||
|
|
||||||
impl header::Header for AccessControlRequestMethod {
|
impl header::Header for AccessControlRequestMethod {
|
||||||
@@ -21,6 +21,6 @@ impl header::Header for AccessControlRequestMethod {
|
|||||||
impl header::HeaderFormat for AccessControlRequestMethod {
|
impl header::HeaderFormat for AccessControlRequestMethod {
|
||||||
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let AccessControlRequestMethod(ref method) = *self;
|
let AccessControlRequestMethod(ref method) = *self;
|
||||||
method.fmt(f)
|
write!(f, "{}", method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ macro_rules! deref(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Exposes the AccessControl* family of headers.
|
/// Exposes the AccessControl* family of headers.
|
||||||
pub mod access_control;
|
pub mod access_control;
|
||||||
|
|
||||||
/// Exposes the Accept header.
|
/// Exposes the Accept header.
|
||||||
|
|||||||
Reference in New Issue
Block a user