Skip to content

feat: expose set_http_client and eval_to_json_with_client#43

Merged
jdx merged 1 commit intomainfrom
feat/http-client-config
Mar 23, 2026
Merged

feat: expose set_http_client and eval_to_json_with_client#43
jdx merged 1 commit intomainfrom
feat/http-client-config

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Mar 23, 2026

Summary

  • Add Evaluator::set_http_client() to configure proxy, CA certs, timeouts, etc.
  • Add eval_to_json_with_client(path, client) convenience function
  • Re-export reqwest so consumers can build a Client without adding reqwest as a separate dependency

This lets hk pass its proxy/CA certificate configuration through to pklr when using the pklr backend.

Test plan

  • cargo test -- all 225 tests pass

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>
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@jdx jdx merged commit 0df4a5f into main Mar 23, 2026
6 checks passed
@jdx jdx deleted the feat/http-client-config branch March 23, 2026 22:05
@jdx jdx mentioned this pull request Mar 23, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 23, 2026

Greptile Summary

This PR exposes HTTP client configuration on pklr's evaluator so callers (e.g. hk) can inject proxy settings, custom CA certificates, and timeouts without having to add reqwest as a direct dependency.

Key changes:

  • Evaluator::set_http_client(client) — new setter that replaces the internal reqwest::Client.
  • eval_to_json_with_client(path, Option<reqwest::Client>) — new top-level convenience function; eval_to_json is cleanly refactored to delegate to it with None.
  • pub use reqwest — re-exports reqwest at the crate root so consumers can construct a Client without pinning a separate reqwest version. Note that the re-exported crate has default-features = false, features = ["rustls-tls"] only; consumers using pklr::reqwest for anything beyond client construction (e.g. the json feature) will find those features absent.
  • One issue found: set_http_client replaces the client but does not clear http_cache. For long-lived Evaluator instances that swap clients mid-session, previously fetched URLs will still be served from cache, bypassing the new client's configuration (proxy, cert pinning, etc.).

Confidence Score: 4/5

  • Safe to merge with minor concern about stale HTTP cache after client replacement.
  • The changes are small, well-scoped, and correct for the primary use case (fresh Evaluator per call via the convenience functions). The one issue — http_cache not being cleared in set_http_client — only affects long-lived Evaluator instances that swap clients mid-session, which is not the advertised usage pattern. The re-export of reqwest is idiomatic and the refactoring of eval_to_json is clean with no behavioral change.
  • src/eval.rs — review the set_http_client implementation regarding cache invalidation.

Important Files Changed

Filename Overview
src/eval.rs Adds set_http_client setter on Evaluator; does not clear http_cache on client replacement, which can cause stale cached responses to be served after a client swap.
src/lib.rs Adds eval_to_json_with_client convenience function and re-exports reqwest; refactors eval_to_json to delegate cleanly — no issues found.

Sequence Diagram

sequenceDiagram
    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
Loading

Fix All in Claude Code

Reviews (1): Last reviewed commit: "feat: expose set_http_client and eval_to..." | Re-trigger Greptile

Comment thread src/eval.rs
Comment on lines +53 to +55
pub fn set_http_client(&mut self, client: reqwest::Client) {
self.http_client = client;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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:

Suggested change
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.

Fix in Claude Code

jdx added a commit that referenced this pull request Mar 23, 2026
## 🤖 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/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant