Skip to content

Commit

Permalink
reqwest improvements: upgrade to version 0.12, disable default feat…
Browse files Browse the repository at this point in the history
…ures, support TLS control

* 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.

* 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.

* Update Cargo.toml

adding these
```
default = ["default-tls"]
default-tls = ["reqwest/default-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
```

as suggested by @max-ipinfo in #60 (comment)

* 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.
  • Loading branch information
aalkhodiry authored Jan 1, 2025
1 parent 36f3a7b commit c1946ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.12", features = ["json"], default-features = false }
lru = "0.12.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -36,3 +36,9 @@ tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
[profile.release]
overflow-checks = true
lto = true

[features]
default = ["default-tls"]
default-tls = ["reqwest/default-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
14 changes: 7 additions & 7 deletions src/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl IpInfo {
) -> Result<HashMap<String, IpDetails>, 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))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit c1946ac

Please sign in to comment.