draft new ggemini api version

This commit is contained in:
yggverse 2024-10-28 02:15:21 +02:00
parent 920721412e
commit 1abda661a7

View file

@ -24,8 +24,7 @@ use gtk::{
RegexMatchFlags, Uri, UriFlags,
},
prelude::{
ActionExt, IOStreamExt, InputStreamExt, OutputStreamExt, SocketClientExt,
StaticVariantType, ToVariant,
ActionExt, IOStreamExt, OutputStreamExt, SocketClientExt, StaticVariantType, ToVariant,
},
Box,
};
@ -362,12 +361,10 @@ impl Page {
// Private helpers @TODO
fn load_gemini(&self, uri: Uri) {
// Use local namespaces
use gemini::client::{
buffer::{Buffer, Error as BufferError},
response::{
use gemini::client::response::{
body::Error as BodyError,
header::{Mime as ClientMime, Status as ClientStatus},
Header,
},
Body, Header,
};
// Init shared objects (async)
@ -423,17 +420,13 @@ impl Page {
None::<&Cancellable>,
move |request| match request {
Ok(_) => {
// Read header from response
connection.input_stream().read_bytes_async(
1024,
Priority::DEFAULT,
None::<&Cancellable>,
move |response| match response {
Ok(bytes) => {
// Read header from response
match Header::from_response(
&bytes
) {
// Read header from input stream
Header::from_socket_connection_async(
connection.clone(),
Some(Priority::DEFAULT),
None::<Cancellable>,
move |result| match result
{
Ok(header) => {
// Route by status
match header.status() {
@ -480,7 +473,7 @@ impl Page {
match header.mime() {
Some(ClientMime::TextGemini) => {
// Read entire input stream to buffer
Buffer::from_connection_async(
Body::from_socket_connection_async(
connection,
move |result|{
match result {
@ -515,11 +508,14 @@ impl Page {
let status = Status::Failure;
let title = gformat!("Oops");
let description = match reason {
BufferError::InputStream => match message {
BodyError::InputStream => match message {
Some(error) => gformat!("{error}"),
None => gformat!("Undefined connection error")
} ,
BufferError::Overflow => gformat!("Buffer overflow"),
BodyError::Overflow => gformat!("Buffer overflow"),
BodyError::Buffer => todo!(),
BodyError::Decode => todo!(),
BodyError::Format => todo!(),
};
// Update widget
@ -642,9 +638,6 @@ impl Page {
},
Err(_) => todo!() // ResponseHeader::from_response
}
}
Err(_) => todo!(), // InputStream::read_bytes_async
},
);
}
Err(_) => todo!(), // OutputStream::write_bytes_async