Fix: rate limit check

main
Leonid Maslakov 4 months ago
parent 7f2470dbfc
commit 6a813f25b4

@ -21,7 +21,6 @@ package netshare
import (
"git.lcomrade.su/root/lenmonitor/internal/storage"
"git.lcomrade.su/root/lenmonitor/internal/tester"
"net"
"net/http"
"strings"
)
@ -35,9 +34,8 @@ func AddServer(req *http.Request, db storage.DB, rateLimit *RateLimit) (string,
}
// Check rate limit
cleanIP, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
return "", "", err
if rateLimit.CheckAndUse(GetClientAddr(req)) == false {
return "", "", ErrTooManyRequests
}
// Get domain and service
@ -53,10 +51,6 @@ func AddServer(req *http.Request, db storage.DB, rateLimit *RateLimit) (string,
return "", "", ErrBadRequest
}
if rateLimit.CheckAndUse(cleanIP) == false {
return "", "", ErrTooManyRequests
}
// Add server
switch srv {
case "lenpaste":

Loading…
Cancel
Save