Repository navigation
Migrate all SDK HTTP requests to HttpClient 5 - #90
Conversation
- Share one HttpClient 5 client per timeout across calls and instances (at most eight), so repeated calls reuse connections as HttpURLConnection did. Idle connections are checked before reuse after 1 s, since automatic retries are off, and kept 5 s unless the server says otherwise. The pool has no per-host limit, so concurrent calls never queue behind it. - Use the JVM proxy and TLS system properties on the client and the connection manager; with the previous builder, https.proxyHost was ignored. - Keep HttpClient's default User-Agent instead of sending none. - Pin httpcore5 and httpcore5-h2 to one version property. - CHANGELOG: list the removed HttpClient 4 dependencies under Removed, and the Content-Type, multipart charset, SLF4J, proxy, User-Agent and connection-reuse changes under Changed. - Tests open HttpClients mocks through HttpClientTestSupport.mockClients(), which drops the shared clients around each mock, and pin the proxy, User-Agent and client sharing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Shared clients run HttpClient's idle-connection evictor (one daemon thread each), closing connections idle for 5 s or past their keep-alive. The pool only closes an idle connection when it is next used, so after a burst of concurrent calls those sockets stayed open indefinitely. Per-call fallback clients skip the evictor; they are closed after the call. - Admit a new timeout value under a lock, re-checking the size there. SHARED.size() and computeIfAbsent() were separate steps: 64 concurrent callers with distinct timeouts got 64 permanent clients instead of 8. - CHANGELOG and AGENTS.md describe the evictor and the eight-value limit instead of saying idle connections are dropped. - Test: 64 callers released together with distinct timeouts get exactly eight shared clients. It fails on the previous commit (64). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Security review: one finding (Medium)Reviewed at HttpClient 5 debug logging writes the API key in plain text, outside the SDK's redaction (CWE-532)Where: Before this PR, the JSON GET/POST paths and all Warmup calls used
When it happens: any app whose SLF4J backend has The old HttpClient 4 multipart and Suggested fixes:
Checked and fine
|
At DEBUG, HttpClient 5 logs the request line (with api_key), every request header (Authorization, API-Key) and the raw request bytes (form fields such as the SMTP password). This is outside the SDK's ZBLogger redaction and can't be turned off from the builder. - README Security: keep org.apache.hc at INFO or above in production; logback with no configuration file logs at DEBUG. - README logging section: "silent by default" covers the SDK's own logging, not HttpClient's. - CHANGELOG: the SLF4J entry names the loggers, and notes that up to 3.0.1 HttpClient 4 and HttpURLConnection logged the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, confirmed. With an SLF4J backend at DEBUG for This isn't new to HC5. The HC4 multipart and HttpClient logs the request line regardless of builder settings, so a test asserting no key at DEBUG can't pass while the key is in the query string. I've documented it instead in bced013: a README Security note next to the existing |
The section opened with "silent by default so it never emits PII", which only holds for the SDK's own ZBLogger. It now says up front that two loggers can write during a request: the SDK's (off until a ZBLogger is registered, key redacted) and HttpClient's, through the app's SLF4J backend, which writes keys and the SMTP password at DEBUG. Adds a complete logback.xml that keeps org.apache.hc at INFO, for apps running Logback with no configuration file (which logs at DEBUG). The Security bullet links to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the SDK from Apache HttpClient 4.5 to HttpClient 5.6. Apache only ships security and major-defect fixes for 4.x and recommends moving to 5.x (status page).
No public API changes.
What changed
SdkHttp.Wire changes worth checking against the live API
validateBatch) sendContent-Type: application/json; charset=UTF-8.HttpURLConnectionused to sendapplication/x-www-form-urlencodedby default.User-AgentisApache-HttpClient/5.6.5 (Java/…)instead ofJava/….org.apache.httpclasses through this SDK now need to declare HttpClient 4 themselves.All of these are in the CHANGELOG.
Testing
Not verified
The live API: I didn't have keys. Running
live/LiveApi.javawithZEROBOUNCE_LIVE_SPEND=1andZEROBOUNCE_LIVE_CHANGES=1would cover the wire changes above.