rsweb 0.9.12

library for creating multithreaded web servers in rust
Documentation
//! # HTTP
//! module containing functions to parse the http protocol
pub mod body;
pub mod cookie;
pub mod header;
pub mod request;
pub mod response;
pub mod status;

pub use request::HTTPRequest;
pub use response::HTTPResponse;

pub use status::StatusCode;
/// enum for supported mime types
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MimeType {
    Html,
    Javascript,
    Css,
    Jpeg,
    Png,
    Pdf,
    Plaintext,
    MultipartFormData,
    WWWFormUrlencoded,
    #[deprecated(since = "0.8.12", note = "use `Custom` instead")]
    Other(String),
    #[deprecated(since = "0.8.12", note = "use `Custom` instead")]
    Wildcard(String, String),
    Custom(String, String),
}

impl MimeType {
    /// make a MimeType from a string and return `None` if it is a non recognizable MimeType
    pub fn from_string(string: String) -> Option<MimeType> {
        match string.as_str() {
            "text/html" => Some(MimeType::Html),
            "text/javascript" => Some(MimeType::Javascript),
            "text/css" => Some(MimeType::Css),
            "image/jpeg" => Some(MimeType::Jpeg),
            "image/png" => Some(MimeType::Png),
            "application/pdf" => Some(MimeType::Pdf),
            "text/pdf" => Some(MimeType::Plaintext),
            "multipart/form-data" => Some(MimeType::MultipartFormData),
            "application/x-www-form-urlencoded" => Some(MimeType::WWWFormUrlencoded),
            n => {
                let mut parts = n.split('/');
                let l = parts.next();
                let r = parts.next();
                if l == None || r == None {
                    None
                } else {
                    let l = l.unwrap();
                    let r = r.unwrap();
                    Some(MimeType::Custom(l.to_string(), r.to_string()))
                }
            }
        }
    }

    /// stringify a mime type
    pub fn to_string(&self) -> String {
        match self {
            MimeType::Html => String::from("text/html"),
            MimeType::Javascript => String::from("text/javascript"),
            MimeType::Css => String::from("text/css"),
            MimeType::Jpeg => String::from("image/jpeg"),
            MimeType::Png => String::from("image/png"),
            MimeType::Pdf => String::from("application/pdf"),
            MimeType::Plaintext => String::from("text/plain"),
            MimeType::MultipartFormData => String::from("multipart/form-data"),
            MimeType::WWWFormUrlencoded => String::from("application/x-www-form-urlencoded"),
            MimeType::Other(n) => n.to_string(),
            MimeType::Wildcard(l, r) => format!("{}/{}", l, r),
            MimeType::Custom(l, r) => format!("{}/{}", l, r),
        }
    }
}

pub use body::Body;