use response::{Response, Responder};
use http::hyper::header;
use http::Status;
#[derive(Debug)]
pub struct Redirect(Status, String);
impl Redirect {
pub fn to(uri: &str) -> Redirect {
Redirect(Status::SeeOther, String::from(uri))
}
pub fn temporary(uri: &str) -> Redirect {
Redirect(Status::TemporaryRedirect, String::from(uri))
}
pub fn permanent(uri: &str) -> Redirect {
Redirect(Status::PermanentRedirect, String::from(uri))
}
pub fn found(uri: &str) -> Redirect {
Redirect(Status::Found, String::from(uri))
}
pub fn moved(uri: &str) -> Redirect {
Redirect(Status::MovedPermanently, String::from(uri))
}
}
impl Responder<'static> for Redirect {
fn respond(self) -> Result<Response<'static>, Status> {
Response::build()
.status(self.0)
.header(header::Location(self.1))
.ok()
}
}