mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
add to_network_address method
This commit is contained in:
parent
4e712260ff
commit
ffda3d27e3
2 changed files with 16 additions and 0 deletions
|
|
@ -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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::fmt::{Display, Formatter, Result};
|
|||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Host,
|
||||
NetworkAddress(crate::gio::network_address::Error),
|
||||
Scheme,
|
||||
Uri(glib::Error),
|
||||
}
|
||||
|
|
@ -13,6 +14,9 @@ impl Display for Error {
|
|||
Self::Host => {
|
||||
write!(f, "Host required")
|
||||
}
|
||||
Self::NetworkAddress(reason) => {
|
||||
write!(f, "Could not parse network address: {reason}")
|
||||
}
|
||||
Self::Scheme => {
|
||||
write!(f, "Scope does not match `gemini`")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue