6895946a34
With this factory, we want to construct ourselves the TLS dialer so that we can use a dialer wrapper that always sets timeouts when reading, addressing https://github.com/ooni/probe/issues/1609. As a result, we cannot immediately replace the i/e/netx factory for creating a new HTTP transport, since the functions signatures are not directly compatible. Refactoring is part of https://github.com/ooni/probe/issues/1505.
29 lines
986 B
Go
29 lines
986 B
Go
package httptransport
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// NewSystemTransport creates a new "system" HTTP transport. That is a transport
|
|
// using the Go standard library with custom dialer and TLS dialer.
|
|
//
|
|
// Deprecation warning
|
|
//
|
|
// New code should use netxlite.NewHTTPTransport instead.
|
|
func NewSystemTransport(config Config) RoundTripper {
|
|
txp := http.DefaultTransport.(*http.Transport).Clone()
|
|
txp.DialContext = config.Dialer.DialContext
|
|
txp.DialTLSContext = config.TLSDialer.DialTLSContext
|
|
// Better for Cloudflare DNS and also better because we have less
|
|
// noisy events and we can better understand what happened.
|
|
txp.MaxConnsPerHost = 1
|
|
// The following (1) reduces the number of headers that Go will
|
|
// automatically send for us and (2) ensures that we always receive
|
|
// back the true headers, such as Content-Length. This change is
|
|
// functional to OONI's goal of observing the network.
|
|
txp.DisableCompression = true
|
|
return txp
|
|
}
|
|
|
|
var _ RoundTripper = &http.Transport{}
|