mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 14:45:28 +00:00
Switch to use Too Many Requests response code
Name the 429 status code
This commit is contained in:
@@ -50,10 +50,6 @@ type defaultAPIServer struct {
|
||||
group *APIGroupVersion
|
||||
}
|
||||
|
||||
const (
|
||||
StatusUnprocessableEntity = 422
|
||||
)
|
||||
|
||||
// Handle returns a Handler function that exposes the provided storage interfaces
|
||||
// as RESTful resources at prefix, serialized by codec, and also includes the support
|
||||
// http resources.
|
||||
|
@@ -24,6 +24,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
|
||||
authhandlers "github.com/GoogleCloudPlatform/kubernetes/pkg/auth/handlers"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
|
||||
@@ -71,9 +72,10 @@ func RateLimit(rl util.RateLimiter, handler http.Handler) http.Handler {
|
||||
handler.ServeHTTP(w, req)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
// Return a 429 status indicating "Too Many Requests"
|
||||
w.WriteHeader(errors.StatusTooManyRequests)
|
||||
w.Header().Set("Retry-After", "1")
|
||||
fmt.Fprintf(w, "Rate limit exceeded.")
|
||||
fmt.Fprintf(w, "Rate limit is 1 QPS or a burst of 20")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -96,7 +98,7 @@ func RecoverPanics(handler http.Handler) http.Handler {
|
||||
http.StatusTemporaryRedirect,
|
||||
http.StatusConflict,
|
||||
http.StatusNotFound,
|
||||
StatusUnprocessableEntity,
|
||||
errors.StatusUnprocessableEntity,
|
||||
),
|
||||
).Log()
|
||||
|
||||
|
Reference in New Issue
Block a user