use std::vec::Vec; #[derive(Copy, Clone)] pub enum Status { Input = 10, Success = 20, Redirect = 30, TemporaryFailure = 40, PermanentFailure = 50, ClientCertificateRequired = 60, } pub struct Header { status: Status, meta: String, } impl Header { pub fn new(status: Status, meta: &str) -> Header { Header { status: status, meta: meta.to_string(), } } pub fn format(&self) -> String { format!("{} {}\r\n", self.status as u8, self.meta) } pub fn to_vec(&self) -> Vec { self.format().as_bytes().to_vec() } } pub fn invalid_protocol() -> Header { Header::new(Status::PermanentFailure, "this protocol is not supported") } pub fn not_understood() -> Header { Header::new(Status::PermanentFailure, "request not understood") } pub fn not_found() -> Header { Header::new(Status::PermanentFailure, "resource not found") } pub fn internal_error() -> Header { Header::new(Status::PermanentFailure, "internal server error") }