mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
refactor(misc): enhance performance on bytes pool, entrypoint, access log and route context handling
- Introduced benchmark tests for Entrypoint and ReverseProxy to evaluate performance. - Updated Entrypoint's ServeHTTP method to improve route context management. - Added new test file for entrypoint benchmarks and refined existing tests for route handling.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package reverseproxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
nettypes "github.com/yusing/go-proxy/internal/net/types"
|
||||
)
|
||||
|
||||
type noopTransport struct{}
|
||||
|
||||
func (t noopTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(strings.NewReader("Hello, world!")),
|
||||
Request: req,
|
||||
ContentLength: int64(len("Hello, world!")),
|
||||
Header: http.Header{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
type noopResponseWriter struct{}
|
||||
|
||||
func (w noopResponseWriter) Header() http.Header {
|
||||
return http.Header{}
|
||||
}
|
||||
|
||||
func (w noopResponseWriter) Write(b []byte) (int, error) {
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (w noopResponseWriter) WriteHeader(statusCode int) {
|
||||
}
|
||||
|
||||
func BenchmarkReverseProxy(b *testing.B) {
|
||||
var w noopResponseWriter
|
||||
var req = http.Request{
|
||||
Method: "GET",
|
||||
URL: &url.URL{Scheme: "http", Host: "test"},
|
||||
Body: io.NopCloser(strings.NewReader("Hello, world!")),
|
||||
}
|
||||
proxy := NewReverseProxy("test", nettypes.MustParseURL("http://localhost:8080"), noopTransport{})
|
||||
for b.Loop() {
|
||||
proxy.ServeHTTP(w, &req)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user