From f5e48abeac382b184287dc30f1a10459fe9cf3c1 Mon Sep 17 00:00:00 2001 From: Abdulrhman Alkhodiry Date: Tue, 17 Dec 2024 15:17:15 +0300 Subject: [PATCH 1/4] Update dependencies in Cargo.toml to disable default features for reqwest and add new feature flags for OpenSSL and Rustls. This enhances control over the used TLS implementation. --- Cargo.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 782f74f..de2d7b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ travis-ci = { repository = "ipinfo/rust", branch = "master" } codecov = { repository = "ipinfo/rust", branch = "master", service = "github" } [dependencies] -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.11", features = ["json"], default-features = false } lru = "0.12.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" @@ -36,3 +36,8 @@ tokio = { version = "1", features = ["rt-multi-thread", "macros"] } [profile.release] overflow-checks = true lto = true + +[features] +default = ["openssl"] +rustls-tls = ["reqwest/rustls-tls"] +openssl = ["reqwest/native-tls"] From 4b2505ee3154a27439b33431591e3107162b849d Mon Sep 17 00:00:00 2001 From: Abdulrhman Alkhodiry Date: Tue, 17 Dec 2024 16:42:22 +0300 Subject: [PATCH 2/4] Upgrade reqwest dependency to version 0.12 - fix tests - update test assertions for IP details to reflect new expected values for city, region, location, postal code, and timezone. --- Cargo.toml | 2 +- src/ipinfo.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index de2d7b8..ccc482e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ travis-ci = { repository = "ipinfo/rust", branch = "master" } codecov = { repository = "ipinfo/rust", branch = "master", service = "github" } [dependencies] -reqwest = { version = "0.11", features = ["json"], default-features = false } +reqwest = { version = "0.12", features = ["json"], default-features = false } lru = "0.12.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/ipinfo.rs b/src/ipinfo.rs index a905bda..1290718 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -584,12 +584,12 @@ mod tests { let ip4 = &details["4.2.2.4"]; assert_eq!(ip4.ip, "4.2.2.4"); assert_eq!(ip4.hostname, Some("d.resolvers.level3.net".to_owned())); - assert_eq!(ip4.city, "Monroe"); - assert_eq!(ip4.region, "Louisiana"); + assert_eq!(ip4.city, "Broomfield"); + assert_eq!(ip4.region, "Colorado"); assert_eq!(ip4.country, "US"); - assert_eq!(ip4.loc, "32.5530,-92.0422"); - assert_eq!(ip4.postal, Some("71203".to_owned())); - assert_eq!(ip4.timezone, Some("America/Chicago".to_owned())); + assert_eq!(ip4.loc, "39.8854,-105.1139"); + assert_eq!(ip4.postal, Some("80021".to_owned())); + assert_eq!(ip4.timezone, Some("America/Denver".to_owned())); } #[tokio::test] From 7ed0299d123d2704b941bb31c51d387166080878 Mon Sep 17 00:00:00 2001 From: Abdulrhman Alkhodiry Date: Wed, 1 Jan 2025 02:58:17 +0300 Subject: [PATCH 3/4] Update Cargo.toml adding these ``` default = ["default-tls"] default-tls = ["reqwest/default-tls"] native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls"] ``` as segussted by @max-ipinfo in https://github.com/ipinfo/rust/pull/60#discussion_r1900233034_ --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccc482e..dec87f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ overflow-checks = true lto = true [features] -default = ["openssl"] +default = ["default-tls"] +default-tls = ["reqwest/default-tls"] +native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls"] -openssl = ["reqwest/native-tls"] From b1c1a8a6c695085d8c8f7ed7faee62e494f5c7b2 Mon Sep 17 00:00:00 2001 From: Abdulrhman Alkhodiry Date: Wed, 1 Jan 2025 16:48:05 +0300 Subject: [PATCH 4/4] Refactor HTTP request formatting in IpInfo implementation - Fixes `the borrowed expression implements the required traits` - Changed string formatting from `format!` to direct string interpolation for POST and GET requests in `ipinfo.rs`. - This improves readability and maintains consistency in the codebase. --- src/ipinfo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipinfo.rs b/src/ipinfo.rs index 1290718..8bf2a21 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -260,7 +260,7 @@ impl IpInfo { ) -> Result, IpError> { // Lookup cache misses which are not bogon let response = client - .post(&format!("{}/batch", BASE_URL)) + .post(format!("{}/batch", BASE_URL)) .headers(Self::construct_headers()) .bearer_auth(self.token.as_deref().unwrap_or_default()) .json(&json!(ips)) @@ -363,7 +363,7 @@ impl IpInfo { // lookup in case of a cache miss let response = self .client - .get(&format!("{}/{}", base_url, ip)) + .get(format!("{}/{}", base_url, ip)) .headers(Self::construct_headers()) .bearer_auth(self.token.as_deref().unwrap_or_default()) .send()