add to_network_address method

This commit is contained in:
yggverse 2024-11-27 18:17:25 +02:00
parent 4e712260ff
commit ffda3d27e3
2 changed files with 16 additions and 0 deletions

View file

@ -1,6 +1,8 @@
pub mod error;
pub use error::Error;
use crate::client::DEFAULT_PORT;
use gio::NetworkAddress;
use glib::{GString, Uri, UriFlags, UriHideFlags};
/// Scope implement path prefix to apply TLS authorization for
@ -38,4 +40,14 @@ impl Scope {
self.uri
.to_string_partial(UriHideFlags::QUERY | UriHideFlags::FRAGMENT)
}
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html)
/// implement [SocketConnectable](https://docs.gtk.org/gio/iface.SocketConnectable.html) interface
/// * useful as [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication) in TLS context
pub fn to_network_address(&self) -> Result<NetworkAddress, Error> {
match crate::gio::network_address::from_uri(&self.uri, DEFAULT_PORT) {
Ok(network_address) => Ok(network_address),
Err(reason) => Err(Error::NetworkAddress(reason)),
}
}
}