Skip to content

Commit

Permalink
cleanup: use NewHTTPTransportWithResolver more often (#808)
Browse files Browse the repository at this point in the history
We can simplify code in a bunch of places using a useful factory.

Part of ooni/probe#2121.
  • Loading branch information
bassosimone authored Jun 8, 2022
1 parent f1b8071 commit beba543
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
5 changes: 1 addition & 4 deletions internal/cmd/oohelper/oohelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 1 addition & 4 deletions internal/cmd/oohelperd/oohelperd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 1 addition & 4 deletions internal/engine/geolocate/iplookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit beba543

Please sign in to comment.