Added host rules + minor refactoring

This commit is contained in:
simon
2019-06-04 22:02:50 -04:00
parent 2b77188ef4
commit 7b0e9a0c13
7 changed files with 513 additions and 81 deletions

View File

@@ -3,10 +3,10 @@ package main
import (
"fmt"
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
"log"
"math"
"net"
"net/http"
"net/url"
"os"
"syscall"
@@ -80,17 +80,9 @@ func waitTime(retries int) time.Duration {
return time.Duration(config.Wait * int64(math.Pow(config.Multiplier, float64(retries))))
}
func (p *Proxy) waitRateLimit(r *http.Request) {
func (p *Proxy) waitRateLimit(limiter *rate.Limiter) {
sHost := simplifyHost(r.Host)
limiter := p.getLimiter(sHost)
reservation := limiter.Reserve()
if !reservation.OK() {
logrus.WithFields(logrus.Fields{
"host": sHost,
}).Warn("Could not get reservation, make sure that burst is > 0")
}
delay := reservation.Delay()
if delay > 0 {