mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 17:45:35 +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,54 +0,0 @@
|
|||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
use glib::GString;
|
||||
|
||||
/// Response meta holder
|
||||
///
|
||||
/// Could be created from entire response buffer or just header slice
|
||||
///
|
||||
/// Use as:
|
||||
/// * placeholder for 10, 11 status
|
||||
/// * URL for 30, 31 status
|
||||
pub struct Meta {
|
||||
value: Option<GString>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
/// Parse Meta from UTF-8
|
||||
pub fn from(buffer: &[u8]) -> Result<Self, Error> {
|
||||
// Init bytes buffer
|
||||
let mut bytes: Vec<u8> = Vec::with_capacity(1021);
|
||||
|
||||
// Skip 3 bytes for status code of 1024 expected
|
||||
match buffer.get(3..1021) {
|
||||
Some(slice) => {
|
||||
for &byte in slice {
|
||||
// End of header
|
||||
if byte == b'\r' {
|
||||
break;
|
||||
}
|
||||
|
||||
// Continue
|
||||
bytes.push(byte);
|
||||
}
|
||||
|
||||
// Assumes the bytes are valid UTF-8
|
||||
match GString::from_utf8(bytes) {
|
||||
Ok(value) => Ok(Self {
|
||||
value: match value.is_empty() {
|
||||
true => None,
|
||||
false => Some(value),
|
||||
},
|
||||
}),
|
||||
Err(_) => Err(Error::Decode),
|
||||
}
|
||||
}
|
||||
None => Err(Error::Protocol),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn value(&self) -> &Option<GString> {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue