mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-02 10:05:36 +00:00
implement all status codes support
This commit is contained in:
parent
d34d24588f
commit
9dd1bcc9dd
1 changed files with 43 additions and 2 deletions
|
|
@ -1,20 +1,42 @@
|
||||||
|
//! Parser and holder API for [Status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes)
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|
||||||
use glib::GString;
|
use glib::GString;
|
||||||
|
|
||||||
/// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
// Input
|
// Input
|
||||||
Input = 10,
|
Input = 10,
|
||||||
SensitiveInput = 11,
|
SensitiveInput = 11,
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
Success = 20,
|
Success = 20,
|
||||||
|
|
||||||
// Redirect
|
// Redirect
|
||||||
Redirect = 30,
|
Redirect = 30,
|
||||||
PermanentRedirect = 31,
|
PermanentRedirect = 31,
|
||||||
} // @TODO
|
|
||||||
|
// Temporary failure
|
||||||
|
TemporaryFailure = 40,
|
||||||
|
ServerUnavailable = 41,
|
||||||
|
CgiError = 42,
|
||||||
|
ProxyError = 43,
|
||||||
|
SlowDown = 44,
|
||||||
|
|
||||||
|
// Permanent failure
|
||||||
|
PermanentFailure = 50,
|
||||||
|
NotFound = 51,
|
||||||
|
ResourceGone = 52,
|
||||||
|
ProxyRequestRefused = 53,
|
||||||
|
BadRequest = 59,
|
||||||
|
|
||||||
|
// Client certificates
|
||||||
|
CertificateRequest = 60,
|
||||||
|
CertificateUnauthorized = 61,
|
||||||
|
CertificateInvalid = 62,
|
||||||
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
|
|
@ -29,11 +51,30 @@ impl Status {
|
||||||
|
|
||||||
pub fn from_string(code: &str) -> Result<Self, Error> {
|
pub fn from_string(code: &str) -> Result<Self, Error> {
|
||||||
match code {
|
match code {
|
||||||
|
// Input
|
||||||
"10" => Ok(Self::Input),
|
"10" => Ok(Self::Input),
|
||||||
"11" => Ok(Self::SensitiveInput),
|
"11" => Ok(Self::SensitiveInput),
|
||||||
|
// Success
|
||||||
"20" => Ok(Self::Success),
|
"20" => Ok(Self::Success),
|
||||||
|
// Redirect
|
||||||
"30" => Ok(Self::Redirect),
|
"30" => Ok(Self::Redirect),
|
||||||
"31" => Ok(Self::PermanentRedirect),
|
"31" => Ok(Self::PermanentRedirect),
|
||||||
|
// Temporary failure
|
||||||
|
"40" => Ok(Self::TemporaryFailure),
|
||||||
|
"41" => Ok(Self::ServerUnavailable),
|
||||||
|
"42" => Ok(Self::CgiError),
|
||||||
|
"43" => Ok(Self::ProxyError),
|
||||||
|
"44" => Ok(Self::SlowDown),
|
||||||
|
// Permanent failure
|
||||||
|
"50" => Ok(Self::PermanentFailure),
|
||||||
|
"51" => Ok(Self::NotFound),
|
||||||
|
"52" => Ok(Self::ResourceGone),
|
||||||
|
"53" => Ok(Self::ProxyRequestRefused),
|
||||||
|
"59" => Ok(Self::BadRequest),
|
||||||
|
// Client certificates
|
||||||
|
"60" => Ok(Self::CertificateRequest),
|
||||||
|
"61" => Ok(Self::CertificateUnauthorized),
|
||||||
|
"62" => Ok(Self::CertificateInvalid),
|
||||||
_ => Err(Error::Undefined),
|
_ => Err(Error::Undefined),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue