Merge pull request #68 from s-panferov/feature/location-header
Add Location header
This commit is contained in:
33
src/header/common/location.rs
Normal file
33
src/header/common/location.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use header::Header;
|
||||
use std::fmt::{mod, Show};
|
||||
use super::from_one_raw_str;
|
||||
|
||||
/// The `Location` header.
|
||||
///
|
||||
/// The Location response-header field is used to redirect the recipient to
|
||||
/// a location other than the Request-URI for completion of the request or identification
|
||||
/// of a new resource. For 201 (Created) responses, the Location is that of the new
|
||||
/// resource which was created by the request. For 3xx responses, the location SHOULD
|
||||
/// indicate the server's preferred URI for automatic redirection to the resource.
|
||||
/// The field value consists of a single absolute URI.
|
||||
///
|
||||
/// Currently is just a String, but it should probably become a better type,
|
||||
/// like url::Url or something.
|
||||
#[deriving(Clone, PartialEq, Show)]
|
||||
pub struct Location(pub String);
|
||||
|
||||
impl Header for Location {
|
||||
fn header_name(_: Option<Location>) -> &'static str {
|
||||
"Location"
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> Option<Location> {
|
||||
from_one_raw_str(raw).map(|s| Location(s))
|
||||
}
|
||||
|
||||
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Location(ref value) = *self;
|
||||
value.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub use self::transfer_encoding::TransferEncoding;
|
||||
pub use self::user_agent::UserAgent;
|
||||
pub use self::server::Server;
|
||||
pub use self::date::Date;
|
||||
pub use self::location::Location;
|
||||
|
||||
use std::from_str::FromStr;
|
||||
use std::str::from_utf8;
|
||||
@@ -46,6 +47,9 @@ pub mod server;
|
||||
/// Exposes the Date header.
|
||||
pub mod date;
|
||||
|
||||
/// Exposes the Location header.
|
||||
pub mod location;
|
||||
|
||||
fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
|
||||
if raw.len() != 1 {
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user