Skip to content

Set Retry-After to the remaining window, not the full length - #64

Open
AshSgDe29071999 wants to merge 1 commit into
go-chi:masterfrom
AshSgDe29071999:fix/retry-after-remaining-window
Open

AshSgDe29071999 wants to merge 1 commit into
go-chi:masterfrom
AshSgDe29071999:fix/retry-after-remaining-window

Conversation

@AshSgDe29071999

Copy link
Copy Markdown

Retry-After always advertised windowLength, so a client limited near the end of a minute still waited a full minute.

Use the time until the current window resets, matching X-RateLimit-Reset.

Fixes #47

Test

go test . -run TestRetryAfterIsRemainingWindow -count=1

The header always advertised windowLength, so a client limited near
the end of a minute still waited a full minute. Use the time until
the current window resets, matching X-RateLimit-Reset.

See go-chi#47
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate
cpu: AMD EPYC 9V45 96-Core Processor                
               │ master.txt  │            pr.txt             │
               │   sec/op    │   sec/op     vs base          │
LocalCounter-4   12.25m ± 0%   12.27m ± 2%  ~ (p=0.436 n=10)

               │  master.txt  │             pr.txt             │
               │     B/op     │     B/op      vs base          │
LocalCounter-4   2.846Mi ± 0%   2.847Mi ± 0%  ~ (p=0.684 n=10)

               │ master.txt  │            pr.txt             │
               │  allocs/op  │  allocs/op   vs base          │
LocalCounter-4   121.5k ± 0%   121.5k ± 0%  ~ (p=0.753 n=10)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retry-After header should maybe not be static

1 participant