feat: expose set_http_client and eval_to_json_with_client#43
Conversation
Allow callers to configure proxy settings, CA certificates, and other HTTP options by providing a custom reqwest::Client to the evaluator. - Add Evaluator::set_http_client() for direct evaluator usage - Add eval_to_json_with_client() convenience function - Re-export reqwest so consumers don't need a separate dependency Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Greptile SummaryThis PR exposes HTTP client configuration on Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant lib as pklr::lib
participant Eval as Evaluator
participant HTTP as reqwest::Client
participant Cache as http_cache
Note over Caller,Cache: eval_to_json_with_client(path, Some(client))
Caller->>lib: eval_to_json_with_client(path, Some(client))
lib->>Eval: Evaluator::new()
lib->>Eval: set_base_path(path.parent())
lib->>Eval: set_http_client(client)
Eval->>HTTP: replace http_client field
lib->>Eval: eval_source(&source, path)
alt remote import encountered
Eval->>Cache: check http_cache[url]
alt cache miss
Eval->>HTTP: client.get(url).send()
HTTP-->>Eval: response body
Eval->>Cache: store in http_cache[url]
else cache hit
Cache-->>Eval: cached body
end
end
Eval-->>lib: Value
lib-->>Caller: serde_json::Value
Note over Caller,Cache: eval_to_json(path) — convenience wrapper
Caller->>lib: eval_to_json(path)
lib->>lib: eval_to_json_with_client(path, None)
Note right of Eval: default reqwest::Client used
Reviews (1): Last reviewed commit: "feat: expose set_http_client and eval_to..." | Re-trigger Greptile |
| pub fn set_http_client(&mut self, client: reqwest::Client) { | ||
| self.http_client = client; | ||
| } |
There was a problem hiding this comment.
Stale HTTP cache after client swap
When set_http_client is called on an Evaluator that has already made HTTP requests, the http_cache will still contain responses fetched via the old client. Any subsequent request to a previously-fetched URL will return the cached response, completely bypassing the new client's proxy/CA/timeout configuration.
For the eval_to_json_with_client convenience function this is harmless (a fresh Evaluator is always constructed), but for callers that hold a long-lived Evaluator and swap clients mid-session the result is surprising — especially in security-sensitive scenarios like certificate pinning or proxy routing.
Consider clearing the cache when the client is replaced:
| pub fn set_http_client(&mut self, client: reqwest::Client) { | |
| self.http_client = client; | |
| } | |
| pub fn set_http_client(&mut self, client: reqwest::Client) { | |
| self.http_client = client; | |
| self.http_cache.clear(); | |
| } |
Alternatively, document in the doc-comment that this method must be called before any HTTP fetching is performed.
## 🤖 New release * `pklr`: 0.2.0 -> 0.2.1 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.2.1](v0.2.0...v0.2.1) - 2026-03-23 ### Added - expose set_http_client and eval_to_json_with_client ([#43](#43)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
Summary
Evaluator::set_http_client()to configure proxy, CA certs, timeouts, etc.eval_to_json_with_client(path, client)convenience functionreqwestso consumers can build aClientwithout adding reqwest as a separate dependencyThis lets hk pass its proxy/CA certificate configuration through to pklr when using the pklr backend.
Test plan
cargo test-- all 225 tests pass