clean up implementation

This commit is contained in:
kirari04
2024-06-11 22:04:30 +02:00
parent 9545343151
commit bb1b161ae2
3 changed files with 16 additions and 7 deletions

View File

@@ -50,6 +50,14 @@ func (t *IpTable) Clear() {
var ipTable = IpTable{}
func (h *ProxyHandler) handleRateLimitRouting(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
err := handleRateLimit(w, r, pe)
if err != nil {
h.logRequest(r, false, 429, "ratelimit", pe.Domain)
}
return err
}
func handleRateLimit(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
@@ -60,7 +68,7 @@ func handleRateLimit(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint)
ipTable.Increment(ip)
if ipTable.Exceeded(ip, 10) {
if ipTable.Exceeded(ip, int64(pe.RateLimit)) {
w.WriteHeader(429)
return errors.New("rate limit exceeded")
}