#[derive(Clone, Debug, PartialEq)]
pub enum AuthChallenge {
Basic,
Digest,
}
#[derive(Clone, Debug, PartialEq)]
pub enum RespComplete {
Resp2xx(Resp2xx),
Resp3xx(Resp3xx),
Resp4xx(Resp4xx),
Resp5xx(Resp5xx),
UncheckedOther(&'static str),
}
impl RespComplete {
pub fn as_bytes_out(&self) -> &[u8] {
match self {
Self::Resp2xx(r) => r.as_bytes_out(),
Self::Resp3xx(r) => r.as_bytes_out(),
Self::Resp4xx(r) => r.as_bytes_out(),
Self::Resp5xx(r) => r.as_bytes_out(),
Self::UncheckedOther(o) => o.as_bytes(),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum RespIndicative {
GoAhead,
R3xx(Resp3xx),
R4xx(Resp4xx),
R5xx(Resp5xx),
}
#[derive(Clone, Debug, PartialEq)]
pub struct StatusDesc {
inner: &'static str,
}
impl StatusDesc {
#[inline]
pub fn new_unchecked(inner: &'static str) -> Self {
Self { inner }
}
pub fn ok() -> Self {
Self { inner: "Ok" }
}
pub fn as_bytes_out(&self) -> &[u8] {
self.inner.as_bytes()
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Resp1xx {
Continue,
SwitchingProtocols,
Processing,
EarlyHints,
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Resp2xx {
Ok,
Created,
Accepted,
NonAuthoritativeInformation,
NoContent,
ResetContent,
PartialContent,
MultiStatus,
AlreadyReported,
ImUsed,
}
impl Resp2xx {
pub fn as_bytes_out(&self) -> &[u8] {
match self {
Self::Ok => "200 OK",
Self::Created => "201 Created",
Self::Accepted => "202 Accepted",
Self::NonAuthoritativeInformation => "203 Non-Authoritative Information",
Self::NoContent => "204 No Content",
Self::ResetContent => "205 Reset Content",
Self::PartialContent => "206 Partial Content",
Self::MultiStatus => "207 Multi-Status",
Self::AlreadyReported => "208 Already Reported",
Self::ImUsed => "226 IM Used",
}
.as_bytes()
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Resp3xx {
MovedPermanently,
Found,
SeeOther,
TempRedirect,
PermRedirect,
}
impl Resp3xx {
pub fn as_bytes_out(&self) -> &[u8] {
match self {
Self::MovedPermanently => "301 Moved Permanently",
Self::Found => "302 Found",
Self::SeeOther => "303 See Other",
Self::TempRedirect => "307 Temporary Redirect",
Self::PermRedirect => "308 Permanent Redirect",
}
.as_bytes()
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Resp4xx {
BadRequest,
AuthRequired(AuthChallenge),
PaymentRequired,
Forbidden,
NotFound,
MethodNotAllowed,
NotAcceptable,
UnsupportedMediaType,
Teapot,
}
impl Resp4xx {
pub fn as_bytes_out(&self) -> &[u8] {
match self {
Self::BadRequest => "400 Bad Request",
Self::AuthRequired(_) => "401 Authentication is required",
Self::PaymentRequired => "402 Payment required",
Self::Forbidden => "403 Forbidden",
Self::NotFound => "404 Not Found",
Self::MethodNotAllowed => "405 Method Not Allowed",
Self::NotAcceptable => "406 Not Acceptable",
Self::UnsupportedMediaType => "415 Unsupported Media Type",
Self::Teapot => "418 I'm a teapot",
}
.as_bytes()
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Resp5xx {
InternalServerError,
NotImplemented,
BadGateway,
ServiceUnavailable,
GatewayTimeout,
HttpVersionNotSupported,
VariantAlsoNegotiates,
InsufficientStorage,
LoopDetected,
BandwidthLimitExceeded,
NotExtended,
NetworkAuthenticationRequired,
}
impl Resp5xx {
pub fn as_bytes_out(&self) -> &[u8] {
match self {
Self::InternalServerError => "500 Internal Server Error",
Self::NotImplemented => "501 Not Implemented",
Self::BadGateway => "502 Bad Gateway",
Self::ServiceUnavailable => "503 Service Unavailable",
Self::GatewayTimeout => "504 Gateway Timeout",
Self::HttpVersionNotSupported => "505 HTTP Version Not Supported",
Self::VariantAlsoNegotiates => "506 Variant Also Negotiates",
Self::InsufficientStorage => "507 Insufficient Storage",
Self::LoopDetected => "508 Loop Detected",
Self::BandwidthLimitExceeded => "509 Bandwidth Limit Exceeded",
Self::NotExtended => "510 Not Extended",
Self::NetworkAuthenticationRequired => "511 Network Authentication Required",
}
.as_bytes()
}
}