mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 09:35:33 +00:00
update api version with new implementation
This commit is contained in:
parent
47f58f800d
commit
93985095a5
14 changed files with 221 additions and 178 deletions
|
|
@ -1,40 +0,0 @@
|
|||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
use glib::GString;
|
||||
|
||||
/// https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
|
||||
#[derive(Debug)]
|
||||
pub enum Status {
|
||||
// 10 | 11
|
||||
Input,
|
||||
SensitiveInput,
|
||||
// 20
|
||||
Success,
|
||||
// 30 | 31
|
||||
Redirect,
|
||||
PermanentRedirect,
|
||||
} // @TODO
|
||||
|
||||
impl Status {
|
||||
pub fn from_header(buffer: &[u8]) -> Result<Self, Error> {
|
||||
match buffer.get(0..2) {
|
||||
Some(value) => match GString::from_utf8(value.to_vec()) {
|
||||
Ok(string) => Self::from_string(string.as_str()),
|
||||
Err(_) => Err(Error::Decode),
|
||||
},
|
||||
None => Err(Error::Protocol),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_string(code: &str) -> Result<Self, Error> {
|
||||
match code {
|
||||
"10" => Ok(Self::Input),
|
||||
"11" => Ok(Self::SensitiveInput),
|
||||
"20" => Ok(Self::Success),
|
||||
"30" => Ok(Self::Redirect),
|
||||
"31" => Ok(Self::PermanentRedirect),
|
||||
_ => Err(Error::Undefined),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue