Skip to content

Commit

Permalink
(NOBIDS) frontend: add headers to responste for ratelimit-api and -va…
Browse files Browse the repository at this point in the history
…lidapikey
  • Loading branch information
guybrush committed Aug 20, 2024
1 parent 5ded67e commit e93582f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ratelimit/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const (
HourTimeWindow = "hour"
MonthTimeWindow = "month"

HeaderRateLimitLimit = "ratelimit-limit" // the rate limit ceiling that is applicable for the current request
HeaderRateLimitRemaining = "ratelimit-remaining" // the number of requests left for the current rate-limit window
HeaderRateLimitReset = "ratelimit-reset" // the number of seconds until the quota resets
HeaderRateLimitWindow = "ratelimit-window" // what window the ratelimit represents
HeaderRetryAfter = "retry-after" // the number of seconds until the quota resets, same as HeaderRateLimitReset, RFC 7231, 7.1.3
HeaderRateLimitLimit = "ratelimit-limit" // the rate limit ceiling that is applicable for the current request
HeaderRateLimitRemaining = "ratelimit-remaining" // the number of requests left for the current rate-limit window
HeaderRateLimitReset = "ratelimit-reset" // the number of seconds until the quota resets
HeaderRateLimitWindow = "ratelimit-window" // what window the ratelimit represents
HeaderRateLimitBucket = "ratelimit-bucket" // bucket for the rate limit
HeaderRateLimitValidApiKey = "ratelimit-validapikey" // if the apikey is valid
HeaderRetryAfter = "retry-after" // the number of seconds until the quota resets, same as HeaderRateLimitReset, RFC 7231, 7.1.3

HeaderRateLimitRemainingSecond = "x-ratelimit-remaining-second" // the number of requests left for the current rate-limit window
HeaderRateLimitRemainingMinute = "x-ratelimit-remaining-minute" // the number of requests left for the current rate-limit window
Expand Down Expand Up @@ -318,6 +320,9 @@ func HttpMiddleware(next http.Handler) http.Handler {
w.Header().Set(HeaderRateLimitRemainingMinute, strconv.FormatInt(rl.RemainingMinute, 10))
w.Header().Set(HeaderRateLimitRemainingSecond, strconv.FormatInt(rl.RemainingSecond, 10))

w.Header().Set(HeaderRateLimitBucket, rl.Bucket)
w.Header().Set(HeaderRateLimitValidApiKey, strconv.FormatBool(rl.IsValidKey))

if rl.BlockRequest {
metrics.Counter.WithLabelValues("ratelimit_block").Inc()
w.Header().Set(HeaderRetryAfter, strconv.FormatInt(rl.Reset, 10))
Expand Down

0 comments on commit e93582f

Please sign in to comment.