diff --git a/src/client/connection.rs b/src/client/connection.rs index 6c4ca3d..842c430 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -9,7 +9,7 @@ pub use response::Response; // Local dependencies use gio::{ - prelude::{IOStreamExt, OutputStreamExtManual, TlsConnectionExt}, + prelude::{IOStreamExt, OutputStreamExt, OutputStreamExtManual, TlsConnectionExt}, Cancellable, IOStream, NetworkAddress, SocketConnection, TlsCertificate, TlsClientConnection, }; use glib::{ @@ -60,23 +60,44 @@ impl Connection { cancellable: Cancellable, callback: impl FnOnce(Result) + 'static, ) { - self.stream().output_stream().write_async( + let output_stream = self.stream().output_stream(); + output_stream.clone().write_async( request.header().into_bytes(), priority, Some(&cancellable.clone()), move |result| match result { - Ok(_) => { - // Read response - Response::from_connection_async(self, priority, cancellable, move |result| { - callback(match result { - Ok(response) => Ok(response), - Err(e) => Err(Error::Response(e)), + Ok(_) => match request { + Request::Gemini(..) => { + Response::from_connection_async(self, priority, cancellable, |result| { + callback(match result { + Ok(response) => Ok(response), + Err(e) => Err(Error::Response(e)), + }) }) - }) - } - Err((b, e)) => callback(Err(Error::Request((b, e)))), + } + Request::Titan(this) => output_stream.write_bytes_async( + &this.data, + priority, + Some(&cancellable.clone()), + move |result| match result { + Ok(_) => Response::from_connection_async( + self, + priority, + cancellable, + |result| { + callback(match result { + Ok(response) => Ok(response), + Err(e) => Err(Error::Response(e)), + }) + }, + ), + Err(e) => callback(Err(Error::Request(e))), + }, + ), + }, + Err((_, e)) => callback(Err(Error::Request(e))), }, - ); + ) } // Getters diff --git a/src/client/connection/error.rs b/src/client/connection/error.rs index fe667e6..178cfba 100644 --- a/src/client/connection/error.rs +++ b/src/client/connection/error.rs @@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter, Result}; #[derive(Debug)] pub enum Error { - Request((Vec, glib::Error)), + Request(glib::Error), Response(crate::client::connection::response::Error), TlsClientConnection(glib::Error), } @@ -10,7 +10,7 @@ pub enum Error { impl Display for Error { fn fmt(&self, f: &mut Formatter) -> Result { match self { - Self::Request((_, e)) => { + Self::Request(e) => { write!(f, "Request error: {e}") } Self::Response(e) => {