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

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 31, 2026
@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6b2b895

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/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue 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/docgen Patch
@effect/doctest Patch
@effect/openapi-generator 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) | 𝕏

const current = getState(key)
const canRetry = options.times === undefined || retries < options.times
function retry(retryAfter: Duration.Duration | undefined) {
if (options.disableResponseInspection) return loop(effect, request)

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.

Was this intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, this was intentional.

retry only receives the value returned by inspectResponse. When disableResponseInspection is true, inspectResponse returns undefined, so retryAfter is always undefined.

In the previous code, this meant the expression below would take the : loop(effect, request) branch, which was the same call made by the separate check. So that check was redundant.

In the updated code, the same path now calls loop(effect, request, retries + 1) to carry the new retry count forward.

@jaipaljadeja
jaipaljadeja requested a review from tim-smart August 4, 2026 06:08
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

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants