feat: add proxy and CA certificate support#30
Conversation
Add two new optional fields to HttpConfig: - proxy: HTTP/HTTPS proxy URL - ca_cert_pem: PEM-encoded CA certificate string Update HttpClient::new() to configure reqwest with proxy and custom root certificate when provided.
Expose proxy and ca_cert parameters in the Python Client constructor, allowing corporate users to configure HTTP proxy and custom CA certs.
Test that Client constructor accepts proxy URL and CA certificate parameters without panicking.
Deploying catsu with
|
| Latest commit: |
5b334d6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aff01f7f.catsu-3ib.pages.dev |
| Branch Preview URL: | https://agent-proxy-ca-cert-support.catsu-3ib.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
catsu-docs | 5b334d6 | Commit Preview URL Branch Preview URL |
Feb 20 2026, 10:19 AM |
There was a problem hiding this comment.
Pull request overview
This PR adds proxy and CA certificate support to the catsu HTTP client, enabling users to configure custom proxies and certificate authorities for corporate environments or special network configurations. The changes are implemented at both the Rust core level and exposed through the Python bindings.
Changes:
- Added
proxyandca_cert_pemfields toHttpConfigstruct - Implemented proxy and CA certificate configuration in
HttpClient::newusing reqwest - Added Python binding parameters
proxyandca_certto theClient.__init__method - Added basic tests for configuration and error handling
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/http.rs | Added proxy and ca_cert_pem fields to HttpConfig, implemented builder pattern to configure reqwest client, added basic tests for config storage |
| packages/python/src/lib.rs | Added proxy and ca_cert parameters to Python Client constructor, mapped them to HttpConfig fields |
| packages/python/tests/test_client.py | Added tests for proxy parameter acceptance, invalid CA certificate handling, valid CA certificate format, and combined options |
Comments suppressed due to low confidence (3)
packages/python/src/lib.rs:184
- The conditional assignments for proxy and ca_cert can be simplified. These unnecessary checks add verbosity without benefit since Option::is_some() followed by assignment is equivalent to direct assignment. Consider simplifying to:
config.proxy = proxy;
config.ca_cert_pem = ca_cert;This matches the pattern used for max_retries and timeout above and is more concise.
if proxy.is_some() {
config.proxy = proxy;
}
if ca_cert.is_some() {
config.ca_cert_pem = ca_cert;
}
packages/python/tests/test_client.py:18
- Consider adding a test for invalid proxy URL handling to match the invalid CA certificate test. This would ensure proper error handling and propagation through the Python bindings when an invalid proxy URL is provided, such as:
def test_client_with_invalid_proxy():
from catsu import Client
with pytest.raises(RuntimeError):
Client(proxy="not a valid url")def test_client_with_invalid_ca_cert():
"""Test that Client raises an error for invalid CA certificate."""
from catsu import Client
with pytest.raises(RuntimeError):
Client(ca_cert="not a valid certificate")
packages/python/tests/test_client.py:36
- The test certificate appears to have repeating placeholder data in the key and signature fields (e.g., "JJ8J8J6jJJ8J..." repeated). While this makes the test more readable as a placeholder, it would be more robust to use an actual minimal valid self-signed certificate to ensure the test accurately reflects real-world usage. The current certificate may fail parsing in ways that don't match how real certificates would fail.
test_cert = """-----BEGIN CERTIFICATE-----
MIIBkTCB+wIJAKHBfpegPjMCMA0GCSqGSIb3DQEBCwUAMBExDzANBgNVBAMMBnVu
dXNlZDAeFw0yMzAxMDEwMDAwMDBaFw0yNDAxMDEwMDAwMDBaMBExDzANBgNVBAMM
BnVudXNlZDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC6fGQKtQ3u3tLGDNnM8Jv2
vHNJJnKJkf8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6j
AgMBAAEwDQYJKoZIhvcNAQELBQADQQBN6V7t8Hy8cWJxmXNvh8J6jJJ8J8J6jJJ8
J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6
-----END CERTIFICATE-----"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #[test] | ||
| fn test_config_with_proxy_and_ca_cert() { | ||
| let config = HttpConfig { | ||
| proxy: Some("http://proxy.example.com:8080".to_string()), | ||
| ca_cert_pem: Some( | ||
| "-----BEGIN CERTIFICATE-----\ntest\n-----END CERTIFICATE-----".to_string(), | ||
| ), | ||
| ..HttpConfig::default() | ||
| }; | ||
| assert_eq!( | ||
| config.proxy, | ||
| Some("http://proxy.example.com:8080".to_string()) | ||
| ); | ||
| assert!(config.ca_cert_pem.is_some()); | ||
| assert!(config.ca_cert_pem.unwrap().contains("BEGIN CERTIFICATE")); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
The Rust tests only verify configuration storage but don't test actual HttpClient construction with proxy and CA certificate. Consider adding a test that constructs an HttpClient with these configurations to ensure they are properly applied to the underlying reqwest client:
#[test]
fn test_http_client_with_proxy() {
let config = HttpConfig {
proxy: Some("http://proxy.example.com:8080".to_string()),
..HttpConfig::default()
};
let client = HttpClient::new(config);
assert!(client.is_ok());
}This would catch any issues with the builder pattern or reqwest integration.
…n test - Use filter to skip empty strings for proxy and ca_cert params - Remove redundant is_some() guards - Document that reqwest respects HTTP_PROXY/HTTPS_PROXY env vars when proxy=None - Add HttpClient::new() test to verify proxy config works at runtime
Adds proxy and CA certificate support to the catsu client.
Changes
Commits