-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[TT-6075] Create option to populate the X-ratelimit headers from rate limits rather than quotas #7730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
API Changes --- prev.txt 2026-02-10 14:50:30.896254510 +0000
+++ current.txt 2026-02-10 14:50:20.311298647 +0000
@@ -6729,6 +6729,12 @@
// JWKS holds the configuration for Tyk JWKS functionalities
JWKS JWKSConfig `json:"jwks"`
+
+ // RateLimitHeadersSource source of rate limit headers
+ RateLimitHeadersSource RateLimitHeadersSource `json:"ratelimit_headers_source"`
+
+ // EnableContextVariables enables extending context data by rate-limit information
+ EnableContextVariables bool `json:"enable_context_variables"`
}
Config is the configuration object used by Tyk to set up various parameters.
@@ -7300,6 +7306,12 @@
func (r *RateLimit) String() string
String returns a readable setting for the rate limiter in effect.
+type RateLimitHeadersSource string
+
+const (
+ RateLimitHeadersSourceQuota RateLimitHeadersSource = "quotas"
+ RateLimitHeadersSourceRateLimit RateLimitHeadersSource = "rate_limits"
+)
type Reporter struct {
// URL connection url to the zipkin server
URL string `json:"url"`
@@ -9990,6 +10002,8 @@
TimeStamp int64
}
+type CtxData = map[string]any
+
type CustomMiddlewareResponseHook struct {
BaseTykResponseHandler
// Has unexported fields.
@@ -11672,7 +11686,7 @@
func (k *RateLimitForAPI) Name() string
-func (k *RateLimitForAPI) ProcessRequest(_ http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
+func (k *RateLimitForAPI) ProcessRequest(rw http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
ProcessRequest will run any checks on the request on the way through the
system, return an error to have the chain fail
@@ -12174,7 +12188,12 @@
SessionLimiter is the rate limiter for the API, use ForwardMessage() to
check if a message should pass through or not
-func NewSessionLimiter(ctx context.Context, conf *config.Config, drlManager *drl.DRL, externalServicesConfig *config.ExternalServiceConfig) SessionLimiter
+func NewSessionLimiter(
+ ctx context.Context,
+ conf *config.Config,
+ drlManager *drl.DRL,
+ externalServicesConfig *config.ExternalServiceConfig,
+) SessionLimiter
NewSessionLimiter initializes the session limiter.
The session limiter initializes the storage required for rate limiters.
@@ -12196,8 +12215,8 @@
dryRun bool,
) sessionFailReason
ForwardMessage will enforce rate limiting, returning a non-zero
- sessionFailReason if session limits have been exceeded. Key values to manage
- rate are Rate and Per, e.g. Rate of 10 messages Per 10 seconds
+ sessionFailReasonMarker if session limits have been exceeded. Key values to
+ manage rate are Rate and Per, e.g. Rate of 10 messages Per 10 seconds
func (l *SessionLimiter) RateLimitInfo(r *http.Request, api *APISpec, endpoints user.Endpoints) (*user.EndpointRateLimitInfo, bool)
@@ -12877,9 +12896,14 @@
upgrade and websocket
const (
- XRateLimitLimit = "X-RateLimit-Limit"
+ // XRateLimitLimit The maximum number of requests that the client is allowed to make in a given time period
+ XRateLimitLimit = "X-RateLimit-Limit"
+
+ // XRateLimitRemaining The number of requests remaining in the current rate limit window.
XRateLimitRemaining = "X-RateLimit-Remaining"
- XRateLimitReset = "X-RateLimit-Reset"
+
+ // XRateLimitReset The number of seconds until the rate limit resets.
+ XRateLimitReset = "X-RateLimit-Reset"
)
Gateway's custom response headers
|
|
This PR introduces a new feature allowing Additionally, a new Files Changed AnalysisThe changes span 30 files, indicating a significant refactoring of the rate-limiting and response-handling logic. Key modifications include:
Architecture & Impact Assessment
sequenceDiagram
participant Client
participant Gateway
participant APIRateLimit Middleware
participant SessionLimiter
participant HeaderSender
Client->>+Gateway: HTTP Request
Gateway->>+APIRateLimit Middleware: ProcessRequest
APIRateLimit Middleware->>+SessionLimiter: ForwardMessage (check limits)
alt Rate Limit Exceeded
SessionLimiter-->>-APIRateLimit Middleware: return sessionFailRateLimit{reset, limit, per}
APIRateLimit Middleware->>+HeaderSender: SendRateLimits(headers, {reset, limit, per})
HeaderSender-->>-APIRateLimit Middleware: Populates X-RateLimit-* headers
APIRateLimit Middleware-->>-Gateway: return Rate Limit Exceeded error
Gateway-->>-Client: 429 Too Many Requests (with headers)
else Request Allowed
SessionLimiter-->>-APIRateLimit Middleware: return sessionFailNone
APIRateLimit Middleware->>Gateway: Continue processing
Note over Gateway,Client: X-RateLimit headers sent from quota on final response
end
Scope Discovery & Context ExpansionThe introduction of This has a direct impact on other powerful features:
Metadata
Powered by Visor from Probelabs Last updated: 2026-02-10T14:52:01.243Z | Triggered by: pr_updated | Commit: ac0fc8b 💡 TIP: You can chat with Visor using |
Security Issues (1)
Architecture Issues (1)
Performance Issues (1)
Quality Issues (2)
Powered by Visor from Probelabs Last updated: 2026-02-10T14:52:09.976Z | Triggered by: pr_updated | Commit: ac0fc8b 💡 TIP: You can chat with Visor using |
bfa0891 to
6cdd71e
Compare
|
/visor Rate limit header should be returned only if 429 is blocked. Here is part of task: "When customers hit rate limits (HTTP 429), they need rate limit information to understand retry timing, but we are showing them quota data instead". Current module (SessionLimiter) needs deeper refactoring. Regarding |
|
Thanks for the clarification. The approach to return rate limit headers specifically on The key change appears to be in the Acknowledged on creating a follow-up ticket to address the deeper refactoring of References:
Powered by Visor from Probelabs Last updated: 2026-02-10T11:04:02.933Z | Triggered by: shults | Commit: edb8c01 💡 TIP: You can chat with Visor using |
99a4cb7 to
24c85a1
Compare
|



Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-6075
Generated at: 2026-02-10 14:49:26