diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-24 00:58:03 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-24 00:58:03 +0800 |
| commit | 6721953fbed98e00d85032a11980fdf75d2ce6da (patch) | |
| tree | 87cd30ae47263961756a862bf526c89a7c425d7a /src/client/connector | |
| parent | c7de2da6f9a966096d15d00cfc2c404fd086ae24 (diff) | |
formattcpserver
Diffstat (limited to 'src/client/connector')
| -rw-r--r-- | src/client/connector/httpconnector.rs | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs index c0dbce0..ac74a7f 100644 --- a/src/client/connector/httpconnector.rs +++ b/src/client/connector/httpconnector.rs @@ -36,35 +36,29 @@ pub struct HTTPConnector { impl HTTPConnector { pub fn new(pull_url: &str, ntfy_url: &str, ip_getter_url: &str) -> result::Result<Self, HTTPConnectorError> { - Ok( - Self { - network_enforcer: Executor::new( - NETWORK_T.as_ref(), - ["true"], - (), - ), // .unwrap() should never panic - prev: String::new(), - pull_url: Url::parse(pull_url)?, - ntfy_url: Url::parse(ntfy_url)?, - ip_getter_url: match Url::parse(ip_getter_url) { - Ok(url) => url, - Err(_) => Url::parse((pull_url.to_string() + ip_getter_url).as_str())?, - }, - client: match Client::builder().build() { + Ok(Self { + network_enforcer: Executor::new(NETWORK_T.as_ref(), ["true"], ()), // .unwrap() should never panic + prev: String::new(), + pull_url: Url::parse(pull_url)?, + ntfy_url: Url::parse(ntfy_url)?, + ip_getter_url: match Url::parse(ip_getter_url) { + Ok(url) => url, + Err(_) => Url::parse((pull_url.to_string() + ip_getter_url).as_str())?, + }, + client: match Client::builder().build() { + Ok(c) => c, + Err(_) => match Client::builder() + .danger_accept_invalid_certs(true) + .build() + { Ok(c) => c, - Err(_) => match Client::builder() + Err(_) => Client::builder() .danger_accept_invalid_certs(true) - .build() - { - Ok(c) => c, - Err(_) => Client::builder() - .danger_accept_invalid_certs(true) - .danger_accept_invalid_hostnames(true) - .build()?, - }, + .danger_accept_invalid_hostnames(true) + .build()?, }, }, - ) + }) } #[allow(clippy::only_used_in_recursion)] @@ -110,28 +104,24 @@ impl Connection for HTTPConnector { // consider StatusCode::NOT_MODIFIED fn update(&self) -> Result<Self::Ok, Self::Err> { - self.handle_response( - || { - self.client - .get( - self.pull_url - .as_str(), - ) - }, - ) + self.handle_response(|| { + self.client + .get( + self.pull_url + .as_str(), + ) + }) } fn ntfy(&self, data: String) -> std::result::Result<(), Self::Err> { - self.handle_response( - || { - self.client - .post( - self.ntfy_url - .as_str(), - ) - .body(data.to_owned()) - }, - )?; + self.handle_response(|| { + self.client + .post( + self.ntfy_url + .as_str(), + ) + .body(data.to_owned()) + })?; Ok(()) } @@ -151,25 +141,21 @@ impl Connection for HTTPConnector { } fn get_ip(&self) -> Option<IpAddr> { - match self.handle_response( - || { - self.client - .get( - self.ip_getter_url - .as_str(), - ) - }, - ) { + match self.handle_response(|| { + self.client + .get( + self.ip_getter_url + .as_str(), + ) + }) { Result::Ok(ip) => Some( ip.parse() .ok()?, ), - Result::Err(_) => match self.handle_response( - || { - self.client - .get("ifconfig.me") - }, - ) { + Result::Err(_) => match self.handle_response(|| { + self.client + .get("ifconfig.me") + }) { Ok(ip) => Some( ip.parse() .ok()?, |
