Skip to content

Add retry and response header options to HttpClient.withRateLimiter - #6827

Open
jaipaljadeja wants to merge 1 commit into
Effect-TS:mainfrom
jaipaljadeja:feat/http-rate-limiter-options
Open

Add retry and response header options to HttpClient.withRateLimiter#6827
jaipaljadeja wants to merge 1 commit into
Effect-TS:mainfrom
jaipaljadeja:feat/http-rate-limiter-options

Conversation

@jaipaljadeja

Copy link
Copy Markdown

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Adds two options to HttpClient.withRateLimiter:

  • times limits the number of automatic retries after a 429 response. It counts retries after the initial request, and times: 0 disables automatic retries. Omitting it preserves the existing unlimited behavior.
  • responseHeaders allows individual rate-limit response header names to be overridden. Fields that are not configured continue using the existing built-in names.

When the retry limit is reached, the final 429 is returned or failed through its original channel. Response inspection still runs before that happens, allowing the limiter to learn from the final response.

Also updates the public API JSDoc and adds runtime and type-level coverage.

Validation:

  • pnpm lint-fix
  • pnpm lint
  • pnpm --filter effect test --run test/unstable/http/HttpClient.test.ts
  • pnpm test-types packages/effect/typetest/unstable/http/HttpClient.tst.ts
  • pnpm check

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 99221ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/platform-node-shared Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • times option — bounds automatic 429 retries. Defaults to undefined (unlimited), 0 disables.
  • responseHeaders option — per-field header name overrides for rate-limit metadata inspection. Unset fields continue using built-in names.
  • Retry-count logiccanRetry gate in both success and error paths, with response inspection running before the gate so the limiter learns from terminal 429s.
  • Tests — custom header parsing, bounded retries (success and error channels), custom Retry-After, terminal 429 feedback with times: 0, header override isolation.
  • Type-level coverage — new options accepted in both data-first and data-last positions.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

Comment thread packages/effect/src/unstable/http/HttpClient.ts
@jaipaljadeja
jaipaljadeja requested a review from tim-smart August 4, 2026 06:08

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Added times option — bounds automatic 429 retries after the initial request. Defaults to unlimited (undefined), and 0 disables retries entirely.
  • Added responseHeaders option — allows per-field override of the header names used for rate-limit inspection (limit, remaining, reset, resetAfter, retryAfter). Unconfigured fields keep the built-in names.
  • Retry-count logiccanRetry gate on both the success and error paths, with response inspection running before the gate so the limiter still learns from terminal 429s.
  • Tests — added coverage for custom limit/reset headers, custom remaining/reset-after headers, header-override isolation (no fallback to built-ins), bounded retries on both success and error channels, custom retry-after header, and Retry-After feedback when retries are disabled.
  • Type-level coveragetimes and responseHeaders accepted in both data-first and data-last positions.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 7.06 KB 7.06 KB 0.00 KB (0.00%)
batching.ts 9.86 KB 9.86 KB 0.00 KB (0.00%)
brand.ts 6.34 KB 6.34 KB 0.00 KB (0.00%)
cache.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
config.ts 20.60 KB 20.60 KB 0.00 KB (0.00%)
differ.ts 20.20 KB 20.20 KB 0.00 KB (0.00%)
http-client.ts 21.53 KB 21.53 KB 0.00 KB (0.00%)
logger.ts 10.84 KB 10.84 KB 0.00 KB (0.00%)
metric.ts 8.98 KB 8.98 KB 0.00 KB (0.00%)
optic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
pubsub.ts 14.99 KB 14.99 KB 0.00 KB (0.00%)
queue.ts 11.66 KB 11.66 KB 0.00 KB (0.00%)
schedule.ts 10.83 KB 10.83 KB 0.00 KB (0.00%)
schema-class.ts 19.14 KB 19.14 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.96 KB 28.96 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.29 KB 25.29 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.38 KB 13.38 KB 0.00 KB (0.00%)
schema-string.ts 10.94 KB 10.94 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.17 KB 15.17 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.94 KB 21.94 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.34 KB 24.34 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.18 KB 19.18 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 19.01 KB 19.01 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.87 KB 18.87 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.60 KB 22.60 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.52 KB 19.52 KB 0.00 KB (0.00%)
schema.ts 18.41 KB 18.41 KB 0.00 KB (0.00%)
stm.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
stream.ts 9.80 KB 9.80 KB 0.00 KB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants