feat: rate-limit ceil Retry-After to superior integer
This commit is contained in:
parent
83a7f10c75
commit
95fabeae73
1 changed files with 2 additions and 1 deletions
|
@ -4,6 +4,7 @@ package ratelimiter
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ func (rl *rateLimiter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *rateLimiter) serveDelayError(ctx context.Context, w http.ResponseWriter, r *http.Request, delay time.Duration) {
|
func (rl *rateLimiter) serveDelayError(ctx context.Context, w http.ResponseWriter, r *http.Request, delay time.Duration) {
|
||||||
w.Header().Set("Retry-After", fmt.Sprintf("%.0f", delay.Seconds()))
|
w.Header().Set("Retry-After", fmt.Sprintf("%.0f", math.Ceil(delay.Seconds())))
|
||||||
w.Header().Set("X-Retry-In", delay.String())
|
w.Header().Set("X-Retry-In", delay.String())
|
||||||
w.WriteHeader(http.StatusTooManyRequests)
|
w.WriteHeader(http.StatusTooManyRequests)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue