refactor: introduce factory for stdlib http transport (#413)

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.
This commit is contained in:
Simone Basso
2021-07-01 15:26:08 +02:00
committed by GitHub
parent f59e98fd05
commit 6895946a34
5 changed files with 115 additions and 3 deletions
@@ -5,6 +5,10 @@ import (
)
// NewHTTP3Transport creates a new HTTP3Transport instance.
//
// Deprecation warning
//
// New code should use netxlite.NewHTTP3Transport instead.
func NewHTTP3Transport(config Config) RoundTripper {
return netxlite.NewHTTP3Transport(config.QUICDialer, config.TLSConfig)
}
@@ -6,6 +6,10 @@ import (
// 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