Repository navigation
only send X-RateLimit headers when a rate limit applies - #262
Conversation
WalkthroughThe middleware now sends ChangesRate-limit response headers
Priority: Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related PRs
Merge Risk:
|
# Conflicts: # docs/content/about/release-notes.md
Summary
RateLimitValidator.CreateMiddlewareininternal/adapter/security/request_rate_limit.gosetX-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reseton every response, unconditionally.result.RateLimitis0when no tier applies (bothper_ip_requests_per_minuteandglobal_requests_per_minuteat0, or an unlimited health probe), so a 200 or a 413 carriedX-RateLimit-Limit: 0andX-RateLimit-Remaining: 0, which a client reads as fully throttled.The three headers are now set only when
result.RateLimit > 0.Retry-Afteron a rejection is unchanged.Type of change
Upgrading
With rate limiting off, responses no longer carry the
X-RateLimit-*headers. Anything that parsed them to detect disabled limits will see them absent. With a limit on, nothing changes. This is in the v0.0.30 upgrading checklist and has its own release note entry.How was this tested?
New in
internal/adapter/security/request_rate_limit_test.go:TestRateLimitValidator_Middleware_RateLimitHeaders, a table over per-IP on, per-IP off with global on (reports the global limit), both off, and an unlimited health probe.Extended in
internal/app/handlers/handler_security_status_codes_test.go:TestSecurityChainMiddleware_OversizedBody_Returns413asserts the three headers are absent on a 413 with both tiers off.Integration
Tested together with the rest of the October round-up (R1 to R5) on
feature/october-round-upatbb64508, a local branch merging all five onto mainfd5e341:make readyandgo test -raceover proxy, security, app and config/olla-validate --quick: 46 pass, 0 fail/claude-code-e2eagainst a real Ollama, passthrough and translation legs: Tier A 16 pass / 0 fail each, no 429s, no retriesChecklist
make readypasses ata4365905docs/content/configuration/practices/rate-limits.md, v0.0.30 release note and upgrading checklistSummary by CodeRabbit