func StartProxy(wg *sync.WaitGroup) { log.Println("Starting proxy server") wg.Add(1) go func() { proxy := goproxy.NewProxyHttpServer(10) proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm) proxy.Verbose = true err := http.ListenAndServe(":54321", proxy) if err != nil { log.Fatal(err.Error()) } wg.Done() }() }
func TestLimiterHttp(t *testing.T) { v := limiter.NewRateLimiter(1, time.Second) proxy := goproxy.NewProxyHttpServer() proxy.OnRequest().Do(limiter.LimitHttp(v)) client, s := oneShotProxy(proxy, t) defer s.Close() r1 := getStatus(srv.URL, client) assert.Equal(t, http.StatusNotFound, r1, "they must be equal") r2 := getStatus(srv.URL, client) assert.Equal(t, http.StatusTooManyRequests, r2, "they must be equal") time.Sleep(1 * time.Second) r3 := getStatus(srv.URL, client) assert.Equal(t, http.StatusNotFound, r3, "they must be equal") }