From bc6b38c1b627c6dcdd50896ded4148dd6e0734ba Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 1 Sep 2025 21:16:52 +0800 Subject: httpconnector: properly parse url --- Cargo.lock | 1 + Cargo.toml | 1 + src/client/connector/connectors/httpconnector.rs | 16 +++++++--------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca49573..e640bde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -792,6 +792,7 @@ version = "0.1.0" dependencies = [ "reqwest", "tokio", + "url", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 81e4123..8c9eece 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] tokio = { version = "1", features = ["full"] } reqwest = { version = "0.12", features = ["blocking"] } +url = { version = "2" } [[bin]] name = "client" diff --git a/src/client/connector/connectors/httpconnector.rs b/src/client/connector/connectors/httpconnector.rs index 2bdb36a..6d501cc 100644 --- a/src/client/connector/connectors/httpconnector.rs +++ b/src/client/connector/connectors/httpconnector.rs @@ -1,24 +1,22 @@ -use std::net::AddrParseError; - use crate::connector::*; -pub(crate) struct HTTPConnector<'a> { +pub(crate) struct HTTPConnector { prev: String, - url: &'a str, + url: reqwest::Url, channel: Channel, } -impl<'a> HTTPConnector<'a> { - pub fn new(url: &'a str) -> Result { +impl HTTPConnector { + pub fn new(url: &str) -> Result { Ok(Self { prev: String::new(), - url, + url: reqwest::Url::parse(url)?, channel: Channel::new(), }) } } -impl Connection for HTTPConnector<'_> { +impl Connection for HTTPConnector { type Err = reqwest::Error; fn test_connection(&self) -> std::result::Result { @@ -26,7 +24,7 @@ impl Connection for HTTPConnector<'_> { } async fn update(&self) -> Option> { - let res = match reqwest::get(self.url).await { + let res = match reqwest::get(self.url.clone()).await { Ok(resp) => match resp.text().await { Ok(text) => text, Err(e) => return Some(Err(e)), -- cgit v1.2.3