summaryrefslogtreecommitdiff
path: root/src/client/connector/connectors
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-01 18:06:03 +0800
commite4a1fbbd596b5466b266a077cddd104933b4fbcf (patch)
treef5baa9e21d9b08c2d401428858505e09c3d1c396 /src/client/connector/connectors
init
Diffstat (limited to 'src/client/connector/connectors')
-rw-r--r--src/client/connector/connectors/httpconnector.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/client/connector/connectors/httpconnector.rs b/src/client/connector/connectors/httpconnector.rs
new file mode 100644
index 0000000..97f79dd
--- /dev/null
+++ b/src/client/connector/connectors/httpconnector.rs
@@ -0,0 +1,45 @@
+use std::net::AddrParseError;
+
+use crate::connector::*;
+
+pub(crate) struct HTTPConnector<'a> {
+ prev: String,
+ url: &'a str,
+ channel: Channel<Self>,
+}
+
+impl<'a> HTTPConnector<'a> {
+ fn new(url: &'a str) -> Result<Self, AddrParseError> {
+ Ok(Self {
+ prev: String::new(),
+ url,
+ channel: Channel::new(),
+ })
+ }
+}
+
+impl Connection for HTTPConnector<'_> {
+ type Err = reqwest::Error;
+
+ fn test_connection(&self) -> std::result::Result<bool, reqwest::Error> {
+ Ok(true)
+ }
+
+ async fn update(&self) -> Option<Result<Self::Success, Self::Err>> {
+ let res = match reqwest::get(self.url).await {
+ Ok(resp) => match resp.text().await {
+ Ok(text) => text,
+ Err(e) => return Some(Err(e)),
+ },
+ Err(e) => return Some(Err(e)),
+ };
+
+ if res == self.prev {
+ return None;
+ }
+
+ _ = self.channel.sender.send(res.clone()); // don't care if receiver is dropped
+
+ Some(Ok(res))
+ }
+}