mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
delegate from_uri method to gio::network_address wrapper
This commit is contained in:
parent
239786da6a
commit
5737b89278
4 changed files with 35 additions and 22 deletions
|
|
@ -11,7 +11,7 @@ pub use response::Response;
|
|||
|
||||
use gio::{
|
||||
prelude::{IOStreamExt, OutputStreamExt, SocketClientExt},
|
||||
Cancellable, NetworkAddress, SocketClient, SocketProtocol, TlsCertificate,
|
||||
Cancellable, SocketClient, SocketProtocol, TlsCertificate,
|
||||
};
|
||||
use glib::{Bytes, Priority, Uri};
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ impl Client {
|
|||
certificate: Option<TlsCertificate>,
|
||||
callback: impl Fn(Result<Response, Error>) + 'static,
|
||||
) {
|
||||
match network_address_for(&uri) {
|
||||
match crate::gio::network_address::from_uri(&uri, DEFAULT_PORT) {
|
||||
Ok(network_address) => {
|
||||
self.socket.connect_async(
|
||||
&network_address.clone(),
|
||||
|
|
@ -78,29 +78,13 @@ impl Client {
|
|||
},
|
||||
);
|
||||
}
|
||||
Err(reason) => callback(Err(reason)),
|
||||
Err(reason) => callback(Err(Error::NetworkAddress(reason))),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
|
||||
/// [SocketConnectable](https://docs.gtk.org/gio/iface.SocketConnectable.html) /
|
||||
/// [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication)
|
||||
fn network_address_for(uri: &Uri) -> Result<NetworkAddress, Error> {
|
||||
Ok(NetworkAddress::new(
|
||||
&match uri.host() {
|
||||
Some(host) => host,
|
||||
None => return Err(Error::Connectable(uri.to_string())),
|
||||
},
|
||||
if uri.port().is_positive() {
|
||||
uri.port() as u16
|
||||
} else {
|
||||
DEFAULT_PORT
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn request_async(
|
||||
connection: Connection,
|
||||
query: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue