Skip to content

Commit

Permalink
Fix cloudflared-rs for wasm and lint warnings (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
joliveirinha authored Dec 7, 2022
1 parent ea24c71 commit c0672aa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cloudflare/src/endpoints/workerskv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
{
let s: Option<i64> = 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)
Expand Down
20 changes: 11 additions & 9 deletions cloudflare/src/framework/async_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ impl Client {
environment: Environment,
) -> anyhow::Result<Client> {
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);
}
}
Expand Down
1 change: 1 addition & 0 deletions cloudflare/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IpAddr>,
}

Expand Down
2 changes: 1 addition & 1 deletion cloudflare/src/framework/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResultType> {
pub result: ResultType,
pub result_info: Option<JsonValue>,
Expand Down

0 comments on commit c0672aa

Please sign in to comment.