feat(http-request): add throwOnError, onRetry, streaming body, parseRetryAfter, sanitizeHeaders#146
Merged
John-David Dalton (jdalton) merged 1 commit intomainfrom Apr 6, 2026
Conversation
…etryAfter, sanitizeHeaders Add new HTTP helpers to enable SDK deduplication: - HttpResponseError class: thrown on non-2xx when throwOnError is enabled - throwOnError option: makes non-2xx responses throw (enabling retry) - onRetry callback: customize retry behavior per-attempt (skip 4xx, honor Retry-After) - Streaming body support: body accepts Readable/FormData, auto-merges getHeaders() - parseRetryAfter(): RFC 7231 Retry-After header parser (strict integer + HTTP-date) - sanitizeHeaders(): redact sensitive headers for safe logging Safety: - Stream bodies rejected with retries > 0 (one-shot, not replayable) - Redirects disabled for stream bodies - settled/resolveOnce/rejectOnce guards prevent double-settle on all paths - rejectOnce destroys stream body to avoid descriptor leaks - res.resume() drains redirect response bodies - emitResponse wrapped in try/catch for hook error resilience - onRetry delay clamped (negative → 0, NaN → default) - maxResponseSize cleanup destroys both response and request
Merged
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HttpResponseErrorclass: thrown on non-2xx whenthrowOnErroris enabled, carries fullHttpResponsethrowOnErroroption onHttpRequestOptions: makes non-2xx responses throw (enabling retry viaretries)onRetrycallback onHttpRequestOptions: customize retry behavior per-attempt (returnfalseto stop,numberto override delay,undefinedfor default)bodyacceptsReadablestreams (incl.form-datanpm package), auto-mergesgetHeaders()when presentparseRetryAfter(): standalone RFC 7231 §7.1.3 Retry-After parser (strict integer seconds + HTTP-date)sanitizeHeaders(): redact sensitive headers (authorization,cookie, etc.) for safe logging/telemetrySafety hardening
retries > 0(one-shot, not replayable)followRedirectsdisabled for stream bodies (consumed on first request)settled/resolveOnce/rejectOnceguards prevent double-settle on all 10+ event pathsrejectOncedestroys stream body to avoid descriptor leaksres.resume()drains redirect response bodies to free socketsemitResponsewrapped in try/catch — user hook errors can't leave promises pendingonRetrydelay clamped (negative → 0, NaN → default)maxResponseSizecleanup destroys both response and requestMotivation
Enables the socket-sdk-js PR #556 to deduplicate with lib — these helpers replace SDK-local implementations of retry logic, header sanitization, Retry-After parsing, and FormData upload plumbing.
Test plan