Use http.RoundTripper instead of http.Transport
Author: paraddiseCreated Aug 18, 2025Updated Dec 3, 2025
In ProxyHttpServer we use http.Transport, bit it's implementation of http.RoundTripper
type ProxyHttpServer struct {
// session variable must be aligned in i386
// see http://golang.org/src/pkg/sync/atomic/doc.go#L41
sess int64
// KeepDestinationHeaders indicates the proxy should retain any headers present in the http.Response before proxying
KeepDestinationHeaders bool
// setting Verbose to true will log information on each request sent to the proxy
Verbose bool
Logger Logger
NonproxyHandler http.Handler
reqHandlers []ReqHandler
respHandlers []RespHandler
httpsHandlers []HttpsHandler
Tr *http.Transport
// ConnectDial will be used to create TCP connections for CONNECT requests
// if nil Tr.Dial will be used
ConnectDial func(network string, addr string) (net.Conn, error)
ConnectDialWithReq func(req *http.Request, network string, addr string) (net.Conn, error)
CertStore CertStorage
KeepHeader bool
}Because of that I can't redefine Tr with my own Round Tripper.
For example I want to to otelhttp.NewTransport(), it returns http.RoundTripper, but I cannot assign it to proxy object.
In such situation I can only use http.Transport, but it doesn't let me intercept requests
Source: elazarl/goproxy