diff --git a/src/client/response/meta.rs b/src/client/response/meta.rs index 9b6c031..0ffcaa6 100644 --- a/src/client/response/meta.rs +++ b/src/client/response/meta.rs @@ -22,9 +22,9 @@ use glib::Priority; pub const MAX_LEN: usize = 0x400; // 1024 pub struct Meta { - data: Data, - mime: Option, status: Status, + data: Option, + mime: Option, // @TODO // charset: Charset, // language: Language, @@ -127,7 +127,7 @@ impl Meta { &self.status } - pub fn data(&self) -> &Data { + pub fn data(&self) -> &Option { &self.data } diff --git a/src/client/response/meta/data.rs b/src/client/response/meta/data.rs index d903f08..737b21c 100644 --- a/src/client/response/meta/data.rs +++ b/src/client/response/meta/data.rs @@ -13,12 +13,15 @@ pub const MAX_LEN: usize = 0x400; // 1024 /// * placeholder for 10, 11 status /// * URL for 30, 31 status pub struct Data { - value: Option, + value: GString, } impl Data { - /// Parse Meta from UTF-8 - pub fn from_utf8(buffer: &[u8]) -> Result { + /// Parse meta data from UTF-8 buffer + /// + /// * result could be `None` for some [status codes](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes) + /// that does not expect any data in header + pub fn from_utf8(buffer: &[u8]) -> Result, Error> { // Init bytes buffer let mut bytes: Vec = Vec::with_capacity(MAX_LEN); @@ -40,11 +43,9 @@ impl Data { // Assumes the bytes are valid UTF-8 match GString::from_utf8(bytes) { - Ok(value) => Ok(Self { - value: match value.is_empty() { - false => Some(value), - true => None, - }, + Ok(value) => Ok(match value.is_empty() { + false => Some(Self { value }), + true => None, }), Err(_) => Err(Error::Decode), } @@ -53,7 +54,7 @@ impl Data { } } - pub fn value(&self) -> &Option { + pub fn value(&self) -> &GString { &self.value } }