mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
implement default_port option for to_network_address method
This commit is contained in:
parent
a2261601f6
commit
fa02234cbd
2 changed files with 12 additions and 6 deletions
|
|
@ -65,7 +65,7 @@ impl Client {
|
|||
// Begin new connection
|
||||
// * [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) required for valid
|
||||
// [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication)
|
||||
match request.to_network_address() {
|
||||
match request.to_network_address(crate::DEFAULT_PORT) {
|
||||
Ok(network_address) => {
|
||||
self.socket
|
||||
.connect_async(&network_address.clone(), Some(&cancellable.clone()), {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,19 @@ impl Request {
|
|||
// Getters
|
||||
|
||||
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`
|
||||
pub fn to_network_address(&self) -> Result<NetworkAddress, Error> {
|
||||
pub fn to_network_address(&self, default_port: u16) -> Result<NetworkAddress, Error> {
|
||||
let uri = match self {
|
||||
Self::Gemini(ref request) => request.uri.clone(),
|
||||
Self::Titan(ref request) => request.uri.clone(),
|
||||
};
|
||||
let port = uri.port();
|
||||
match crate::gio::network_address::from_uri(
|
||||
&match self {
|
||||
Self::Gemini(ref request) => request.uri.clone(),
|
||||
Self::Titan(ref request) => request.uri.clone(),
|
||||
&uri,
|
||||
if port.is_positive() {
|
||||
port as u16
|
||||
} else {
|
||||
default_port
|
||||
},
|
||||
crate::DEFAULT_PORT,
|
||||
) {
|
||||
Ok(network_address) => Ok(network_address),
|
||||
Err(e) => Err(Error::NetworkAddress(e)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue