add rate limiting support for REST API/web admin too

This commit is contained in:
Nicola Murino
2021-04-19 08:14:04 +02:00
parent 112e3b2fc2
commit f45c89fc46
15 changed files with 109 additions and 39 deletions

View File

@@ -158,7 +158,10 @@ func (s *webDavServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, common.ErrConnectionDenied.Error(), http.StatusForbidden)
return
}
if err := common.LimitRate(common.ProtocolWebDAV, ipAddr); err != nil {
delay, err := common.LimitRate(common.ProtocolWebDAV, ipAddr)
if err != nil {
w.Header().Set("Retry-After", fmt.Sprintf("%.0f", delay.Seconds()))
w.Header().Set("X-Retry-In", delay.String())
http.Error(w, err.Error(), http.StatusTooManyRequests)
return
}