diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-01 21:16:52 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-01 21:16:52 +0800 |
| commit | bc6b38c1b627c6dcdd50896ded4148dd6e0734ba (patch) | |
| tree | 98438f790e68e447dd95abd570826199dd4758f0 | |
| parent | ad6eb932bc7a2158627d83a9f8a1785b89338afe (diff) | |
httpconnector: properly parse url
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/client/connector/connectors/httpconnector.rs | 16 |
3 files changed, 9 insertions, 9 deletions
@@ -792,6 +792,7 @@ version = "0.1.0" dependencies = [ "reqwest", "tokio", + "url", ] [[package]] @@ -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<Self>, } -impl<'a> HTTPConnector<'a> { - pub fn new(url: &'a str) -> Result<Self, AddrParseError> { +impl HTTPConnector { + pub fn new(url: &str) -> Result<Self, url::ParseError> { 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<bool, reqwest::Error> { @@ -26,7 +24,7 @@ impl Connection for HTTPConnector<'_> { } async fn update(&self) -> Option<Result<Self::Success, Self::Err>> { - 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)), |
