c74c94d616
We are not using them anymore. The only nettest still using the legacy netx implementation is tor, for which setting these fields is useless, because it performs each measurement into a separate goroutine. Hence, let us start removing this part of the legacy netx codebase, which is hampering progress in other areas. Occurred to me while doing testing for the recent changes in error mapping (https://github.com/ooni/probe/issues/1505).
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Package oldhttptransport contains HTTP transport extensions. Here we
|
|
// define a http.Transport that emits events.
|
|
package oldhttptransport
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// Transport performs single HTTP transactions and emits
|
|
// measurement events as they happen.
|
|
type Transport struct {
|
|
roundTripper http.RoundTripper
|
|
}
|
|
|
|
// New creates a new Transport.
|
|
func New(roundTripper http.RoundTripper) *Transport {
|
|
return &Transport{
|
|
roundTripper: NewBodyTracer(NewTraceTripper(roundTripper)),
|
|
}
|
|
}
|
|
|
|
// RoundTrip executes a single HTTP transaction, returning
|
|
// a Response for the provided Request.
|
|
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
|
// Make sure we're not sending Go's default User-Agent
|
|
// if the user has configured no user agent
|
|
if req.Header.Get("User-Agent") == "" {
|
|
req.Header["User-Agent"] = nil
|
|
}
|
|
return t.roundTripper.RoundTrip(req)
|
|
}
|
|
|
|
// CloseIdleConnections closes the idle connections.
|
|
func (t *Transport) CloseIdleConnections() {
|
|
// Adapted from net/http code
|
|
type closeIdler interface {
|
|
CloseIdleConnections()
|
|
}
|
|
if tr, ok := t.roundTripper.(closeIdler); ok {
|
|
tr.CloseIdleConnections()
|
|
}
|
|
}
|