2019-03-14 08:30:04 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2021-03-04 19:08:03 +00:00
|
|
|
"io"
|
2019-03-14 08:30:04 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/testhelpers"
|
2019-03-14 08:30:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type staticTransport struct {
|
|
|
|
res *http.Response
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *staticTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
|
|
return t.res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkProxy(b *testing.B) {
|
|
|
|
res := &http.Response{
|
2022-08-09 15:36:08 +00:00
|
|
|
StatusCode: http.StatusOK,
|
2021-03-04 19:08:03 +00:00
|
|
|
Body: io.NopCloser(strings.NewReader("")),
|
2019-03-14 08:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
|
|
|
|
|
|
|
pool := newBufferPool()
|
2022-11-16 10:38:07 +00:00
|
|
|
handler := buildSingleHostProxy(req.URL, false, 0, &staticTransport{res}, pool)
|
2019-03-14 08:30:04 +00:00
|
|
|
|
|
|
|
b.ReportAllocs()
|
2024-02-19 14:44:03 +00:00
|
|
|
for range b.N {
|
2019-03-14 08:30:04 +00:00
|
|
|
handler.ServeHTTP(w, req)
|
|
|
|
}
|
|
|
|
}
|