arara-cgi 1.0.0

A arara dependecie
Documentation
use std::collections::HashMap;
use std::{fmt, mem, ptr};

pub enum StatusCode {
    Custom(u32, String),

    Continue,
    SwitchingProtocols,
    Processing,
    EarlyHints,

    OK,
    Created,
    Accepted,
    NonAuthoritativeInformation,
    NoContent,
    ResetContent,
    PartialContent,
    MultiStatus,
    AlreadyReported,
    IMUsed,

    MultipleChoices,
    MovedPermanently,
    Found,
    SeeOther,
    NotModified,
    UseProxy,
    SwitchProxy,
    TemporaryRedirect,
    PermanentRedirect,

    BadRequest, 
    Unauthorized,
    PaymentRequired,
    Forbidden,
    NotFound,
    MethodNotAllowed,
    NotAcceptable,
    ProxyAuthenticationRequired,
    RequestTimeout,
    Conflict,
    Gone,
    LengthRequired,
    PreconditionFailed,
    PayloadTooLarge,
    URITooLong,
    UnsupportedMediaType,
    RangeNotSatisfiable,
    ExpectationFailed,
    IMTeapot,
    MisdirectedRequest,
    UnprocessableContent,
    Locked,
    FailedDependency,
    TooEarly,
    UpgradeRequired,
    PreconditionRequired,
    TooManyRequests,
    RequestHeaderFieldsTooLarge,
    UnavailableForLegalReasons,

    InternalServerError,
    NotImplemented,
    BadGateway,
    ServiceUnavailable,
    GatewayTimeout,
    HTTPVersionNotSupported,
    VariantAlsoNegotiates,
    InsufficientStorage,
    LoopDetected,
    NotExtended,
    NetworkAuthenticationRequired
}

impl fmt::Display for StatusCode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let status_str: String = match self {
            Self::Custom(code, status) => format!("{} {}", code, status),

            Self::Continue => String::from("100 Continue"),
            Self::SwitchingProtocols => String::from("101 Switching Protocols"),
            Self::Processing => String::from("102 Processing"),
            Self::EarlyHints => String::from("103 Early Hints"),

            Self::OK => String::from("200 OK"),
            Self::Created => String::from("201 Created"),
            Self::Accepted => String::from("202 Accepted"),
            Self::NonAuthoritativeInformation => String::from("203 Non-Authoritative Information"),
            Self::NoContent => String::from("204 No Content"),
            Self::ResetContent => String::from("205 Reset Content"),
            Self::PartialContent => String::from("206 Partial Content"),
            Self::MultiStatus => String::from("207 Multi-Status"),
            Self::AlreadyReported => String::from("208 Already Reported"),
            Self::IMUsed => String::from("226 IM Used"),

            Self::MultipleChoices => String::from("300 Multiple Choices"),
            Self::MovedPermanently => String::from("301 Moved Permanently"),
            Self::Found => String::from("302 Found"),
            Self::SeeOther => String::from("303 See Other"),
            Self::NotModified => String::from("304 Not Modified"),
            Self::UseProxy => String::from("305 Use Proxy"),
            Self::SwitchProxy => String::from("306 Switch Proxy"),
            Self::TemporaryRedirect => String::from("307 Temporary Redirect"),
            Self::PermanentRedirect => String::from("308 Permanent Redirect"),

            Self::BadRequest => String::from("400 Bad Request"), 
            Self::Unauthorized => String::from("401 Unauthorized"),
            Self::PaymentRequired => String::from("402 Payment Required"),
            Self::Forbidden => String::from("403 Forbidden"),
            Self::NotFound => String::from("404 Not Found"),
            Self::MethodNotAllowed => String::from("405 Method Not Allowed"),
            Self::NotAcceptable => String::from("406 Not Acceptable"),
            Self::ProxyAuthenticationRequired => String::from("407 Proxy Authentication Required"),
            Self::RequestTimeout => String::from("408 Request Timeout"),
            Self::Conflict => String::from("409 Conflict"),
            Self::Gone => String::from("410 Gone"),
            Self::LengthRequired => String::from("411 Length Required"),
            Self::PreconditionFailed => String::from("412 Precondition Failed"),
            Self::PayloadTooLarge => String::from("413 Payload Too Large"),
            Self::URITooLong => String::from("414 URI Too Long"),
            Self::UnsupportedMediaType => String::from("415 Unsupported Media Type"),
            Self::RangeNotSatisfiable => String::from("416 Range Not Satisfiable"),
            Self::ExpectationFailed => String::from("417 Expectation Failed"),
            Self::IMTeapot => String::from("418 I'm a teapot"),
            Self::MisdirectedRequest => String::from("421 Misdirected Request"),
            Self::UnprocessableContent => String::from("422 Unprocessable Entity"),
            Self::Locked => String::from("423 Locked"),
            Self::FailedDependency => String::from("424 Failed Dependency"),
            Self::TooEarly => String::from("425 Too Early"),
            Self::UpgradeRequired => String::from("426 Upgrade Required"),
            Self::PreconditionRequired => String::from("428 Precondition Required"),
            Self::TooManyRequests => String::from("429 Too Many Requests"),
            Self::RequestHeaderFieldsTooLarge => String::from("431 Request Header Fields Too Large"),
            Self::UnavailableForLegalReasons => String::from("451 Unavailable For Legal Reasons"),

            Self::InternalServerError => String::from("500 Internal Server Error"),
            Self::NotImplemented => String::from("501 Not Implemented"),
            Self::BadGateway => String::from("502 Bad Gateway"),
            Self::ServiceUnavailable => String::from("503 Service Unavailable"),
            Self::GatewayTimeout => String::from("504 Gateway Timeout"),
            Self::HTTPVersionNotSupported => String::from("505 HTTP Version Not Supported"),
            Self::VariantAlsoNegotiates => String::from("506 Variant Also Negotiates"),
            Self::InsufficientStorage => String::from("507 Insufficient Storage"),
            Self::LoopDetected => String::from("508 Loop Detected"),
            Self::NotExtended => String::from("510 Not Extended"),
            Self::NetworkAuthenticationRequired => String::from("511 Network Authentication Required"),
        };

        write!(f, "{}", status_str)
    }

}

pub struct Response {
    pub status: StatusCode,
    pub content_type: &'static str,
    pub headers: HashMap<String, String>,
    pub body: &'static str,
}

impl Response {
    pub fn new() -> Self {
        Self {
            status: StatusCode::OK,
            content_type: "",
            headers: HashMap::new(),
            body: ""
        }
    }
}