From beba543b98109d5705912caab07ed86926cdd10d Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 8 Jun 2022 15:13:01 +0200 Subject: [PATCH] cleanup: use NewHTTPTransportWithResolver more often (#808) We can simplify code in a bunch of places using a useful factory. Part of https://github.com/ooni/probe/issues/2121. --- internal/cmd/oohelper/oohelper.go | 5 +---- internal/cmd/oohelperd/oohelperd.go | 5 +---- internal/engine/geolocate/iplookup.go | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/internal/cmd/oohelper/oohelper.go b/internal/cmd/oohelper/oohelper.go index 5ac8987..da9f85e 100644 --- a/internal/cmd/oohelper/oohelper.go +++ b/internal/cmd/oohelper/oohelper.go @@ -29,10 +29,7 @@ func init() { // puzzling https://github.com/ooni/probe/issues/1409 issue. const resolverURL = "https://8.8.8.8/dns-query" resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, resolverURL) - thx := netxlite.NewTLSHandshakerStdlib(log.Log) - dialer := netxlite.NewDialerWithResolver(log.Log, resolver) - tlsDialer := netxlite.NewTLSDialer(dialer, thx) - txp := netxlite.NewHTTPTransport(log.Log, dialer, tlsDialer) + txp := netxlite.NewHTTPTransportWithResolver(log.Log, resolver) httpClient = netxlite.NewHTTPClient(txp) } diff --git a/internal/cmd/oohelperd/oohelperd.go b/internal/cmd/oohelperd/oohelperd.go index 9da6446..007cdf5 100644 --- a/internal/cmd/oohelperd/oohelperd.go +++ b/internal/cmd/oohelperd/oohelperd.go @@ -32,10 +32,7 @@ func init() { // default resolver configured by the box. Also, use an encrypted transport thus // we're less vulnerable to any policy implemented by the box's provider. resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, "https://8.8.8.8/dns-query") - thx := netxlite.NewTLSHandshakerStdlib(log.Log) - dialer = netxlite.NewDialerWithResolver(log.Log, resolver) - tlsDialer := netxlite.NewTLSDialer(dialer, thx) - txp := netxlite.NewHTTPTransport(log.Log, dialer, tlsDialer) + txp := netxlite.NewHTTPTransportWithResolver(log.Log, resolver) httpClient = netxlite.NewHTTPClient(txp) } diff --git a/internal/engine/geolocate/iplookup.go b/internal/engine/geolocate/iplookup.go index 155e8e0..f041474 100644 --- a/internal/engine/geolocate/iplookup.go +++ b/internal/engine/geolocate/iplookup.go @@ -86,10 +86,7 @@ func (c ipLookupClient) doWithCustomFunc( // Implementation note: we MUST use an HTTP client that we're // sure IS NOT using any proxy. To this end, we construct a // client ourself that we know is not proxied. - dialer := netxlite.NewDialerWithResolver(c.Logger, c.Resolver) - handshaker := netxlite.NewTLSHandshakerStdlib(c.Logger) - tlsDialer := netxlite.NewTLSDialer(dialer, handshaker) - txp := netxlite.NewHTTPTransport(c.Logger, dialer, tlsDialer) + txp := netxlite.NewHTTPTransportWithResolver(c.Logger, c.Resolver) clnt := &http.Client{Transport: txp} defer clnt.CloseIdleConnections() ip, err := fn(ctx, clnt, c.Logger, c.UserAgent)