update request api

This commit is contained in:
yggverse 2025-01-22 15:14:59 +02:00
parent 52141f3dca
commit 5e52e74870
6 changed files with 37 additions and 78 deletions

View file

@ -1,4 +1,4 @@
use glib::{Bytes, Uri};
use glib::Uri;
/// [Gemini](https://geminiprotocol.net/docs/protocol-specification.gmi) protocol enum object for `Request`
pub struct Gemini {
@ -8,8 +8,8 @@ pub struct Gemini {
impl Gemini {
// Getters
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
pub fn to_bytes(&self) -> Bytes {
Bytes::from(format!("{}\r\n", self.uri).as_bytes())
/// Get header string for `Self`
pub fn header(&self) -> String {
format!("{}\r\n", self.uri)
}
}

View file

@ -3,7 +3,7 @@ use glib::{Bytes, Uri, UriHideFlags};
/// [Titan](gemini://transjovian.org/titan/page/The%20Titan%20Specification) protocol enum object for `Request`
pub struct Titan {
pub uri: Uri,
pub data: Vec<u8>,
pub data: Bytes,
pub mime: Option<String>,
pub token: Option<String>,
}
@ -11,8 +11,8 @@ pub struct Titan {
impl Titan {
// Getters
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
pub fn to_bytes(&self) -> Bytes {
/// Get header string for `Self`
pub fn header(&self) -> String {
// Calculate data size
let size = self.data.len();
@ -31,13 +31,6 @@ impl Titan {
header.push_str(&format!("?{query}"));
}
header.push_str("\r\n");
// Build request
let mut bytes: Vec<u8> = Vec::with_capacity(size + 1024); // @TODO
bytes.extend(header.into_bytes());
bytes.extend(&self.data);
// Wrap result
Bytes::from(&bytes)
header
}
}