From c0672aa50b5560a5a50ad3d7528e409d56335f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveirinha?= Date: Wed, 7 Dec 2022 09:45:22 +0000 Subject: [PATCH] Fix cloudflared-rs for wasm and lint warnings (#196) --- cloudflare/src/endpoints/workerskv/mod.rs | 2 +- cloudflare/src/framework/async_api.rs | 20 +++++++++++--------- cloudflare/src/framework/mod.rs | 1 + cloudflare/src/framework/response/mod.rs | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cloudflare/src/endpoints/workerskv/mod.rs b/cloudflare/src/endpoints/workerskv/mod.rs index f8637acf..f56824d4 100644 --- a/cloudflare/src/endpoints/workerskv/mod.rs +++ b/cloudflare/src/endpoints/workerskv/mod.rs @@ -70,7 +70,7 @@ where { let s: Option = Option::deserialize(deserializer)?; if let Some(s) = s { - return Ok(Some(Utc.timestamp(s, 0))); + return Ok(Utc.timestamp_opt(s, 0).single()); } Ok(None) diff --git a/cloudflare/src/framework/async_api.rs b/cloudflare/src/framework/async_api.rs index 1b042d2e..ed89938b 100644 --- a/cloudflare/src/framework/async_api.rs +++ b/cloudflare/src/framework/async_api.rs @@ -47,18 +47,20 @@ impl Client { environment: Environment, ) -> anyhow::Result { let mut builder = reqwest::Client::builder().default_headers(config.default_headers); - if let Some(address) = config.resolve_ip { - let url = url::Url::from(&environment); - builder = builder.resolve( - url.host_str() - .expect("Environment url should have a hostname"), - SocketAddr::new(address, 443), - ); - } cfg_if! { - // There are no timeouts in wasm. The property is documented as no-op in wasm32. if #[cfg(not(target_arch = "wasm32"))] { + // There is no resolve method in wasm. + if let Some(address) = config.resolve_ip { + let url = url::Url::from(&environment); + builder = builder.resolve( + url.host_str() + .expect("Environment url should have a hostname"), + SocketAddr::new(address, 443), + ); + } + + // There are no timeouts in wasm. The property is documented as no-op in wasm32. builder = builder.timeout(config.http_timeout); } } diff --git a/cloudflare/src/framework/mod.rs b/cloudflare/src/framework/mod.rs index d3f2687c..2c715cf4 100644 --- a/cloudflare/src/framework/mod.rs +++ b/cloudflare/src/framework/mod.rs @@ -71,6 +71,7 @@ pub struct HttpApiClientConfig { /// A default set of HTTP headers which will be sent with each API request. pub default_headers: http::HeaderMap, /// A specific IP to use when establishing a connection + /// Note: this configuration has no effect when the target is wasm32. pub resolve_ip: Option, } diff --git a/cloudflare/src/framework/response/mod.rs b/cloudflare/src/framework/response/mod.rs index 398843aa..3711dd33 100644 --- a/cloudflare/src/framework/response/mod.rs +++ b/cloudflare/src/framework/response/mod.rs @@ -5,7 +5,7 @@ mod apifail; pub use apifail::*; use serde_json::value::Value as JsonValue; -#[derive(Deserialize, Debug, PartialEq)] +#[derive(Deserialize, Debug, Eq, PartialEq)] pub struct ApiSuccess { pub result: ResultType, pub result_info: Option,