summaryrefslogtreecommitdiff
path: root/src/client/connector
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/connector')
-rw-r--r--src/client/connector/httpconnector.rs104
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()?,