From 4f75bc1b3fd85a7b54cf6bbb6e895c2deb353299 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 14 Sep 2025 00:29:34 +0800 Subject: feat(executor): integrate into httpconnector cleanup: main --- src/client/connector/connectors/httpconnector.rs | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/client/connector') diff --git a/src/client/connector/connectors/httpconnector.rs b/src/client/connector/connectors/httpconnector.rs index 2a7c0d8..923df94 100644 --- a/src/client/connector/connectors/httpconnector.rs +++ b/src/client/connector/connectors/httpconnector.rs @@ -1,4 +1,4 @@ -use reqwest::{Error, StatusCode, Url, blocking::get}; +use reqwest::{Error, StatusCode, Url, blocking::Client}; use crate::connector::*; use std::{thread::sleep, time::Duration}; @@ -6,13 +6,16 @@ use std::{thread::sleep, time::Duration}; pub(crate) struct HTTPConnector { prev: String, url: Url, + client: Client, } impl HTTPConnector { - pub fn new(url: &str) -> Result { + pub fn new(url: &str) -> std::result::Result { Ok(Self { prev: String::new(), url: Url::parse(url)?, + // TODO: keep alive + client: Client::new(), }) } } @@ -34,8 +37,8 @@ impl std::fmt::Display for Err { impl Connection for HTTPConnector { type Err = Err; - fn update(&self) -> Option> { - let res = match get(self.url.as_str()) { + fn update(&self) -> Option> { + let resp = match self.client.get(self.url.as_str()).send() { Ok(resp) => match resp.status() { StatusCode::TOO_MANY_REQUESTS => { sleep(Duration::from_secs(5)); @@ -43,23 +46,25 @@ impl Connection for HTTPConnector { } status => { if !status.is_success() { - return Some(Err(Err::StatusCode(status))); + return Some(Result::Err(Err::StatusCode(status))); } match resp.text() { Ok(text) => text, - Err(e) => return Some(Err(Err::Reqwest(e))), + Err(e) => return Some(Result::Err(Err::Reqwest(e))), } } }, - Err(e) => return Some(Err(Err::Reqwest(e))), + Err(e) => return Some(Result::Err(Err::Reqwest(e))), }; - if res == self.prev { + if resp == self.prev { return None; } - Some(Ok(res)) + Some(Result::Ok(resp)) } - // fn ntfy(&self, data: T) {} + fn ntfy(&self, data: String) { + println!("{}", data) + } } -- cgit v1.2.3