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