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.
This commit is contained in:
parent
f1b8071c65
commit
beba543b98
|
@ -29,10 +29,7 @@ func init() {
|
||||||
// puzzling https://github.com/ooni/probe/issues/1409 issue.
|
// puzzling https://github.com/ooni/probe/issues/1409 issue.
|
||||||
const resolverURL = "https://8.8.8.8/dns-query"
|
const resolverURL = "https://8.8.8.8/dns-query"
|
||||||
resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, resolverURL)
|
resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, resolverURL)
|
||||||
thx := netxlite.NewTLSHandshakerStdlib(log.Log)
|
txp := netxlite.NewHTTPTransportWithResolver(log.Log, resolver)
|
||||||
dialer := netxlite.NewDialerWithResolver(log.Log, resolver)
|
|
||||||
tlsDialer := netxlite.NewTLSDialer(dialer, thx)
|
|
||||||
txp := netxlite.NewHTTPTransport(log.Log, dialer, tlsDialer)
|
|
||||||
httpClient = netxlite.NewHTTPClient(txp)
|
httpClient = netxlite.NewHTTPClient(txp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,7 @@ func init() {
|
||||||
// default resolver configured by the box. Also, use an encrypted transport thus
|
// 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.
|
// 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")
|
resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, "https://8.8.8.8/dns-query")
|
||||||
thx := netxlite.NewTLSHandshakerStdlib(log.Log)
|
txp := netxlite.NewHTTPTransportWithResolver(log.Log, resolver)
|
||||||
dialer = netxlite.NewDialerWithResolver(log.Log, resolver)
|
|
||||||
tlsDialer := netxlite.NewTLSDialer(dialer, thx)
|
|
||||||
txp := netxlite.NewHTTPTransport(log.Log, dialer, tlsDialer)
|
|
||||||
httpClient = netxlite.NewHTTPClient(txp)
|
httpClient = netxlite.NewHTTPClient(txp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,10 +86,7 @@ func (c ipLookupClient) doWithCustomFunc(
|
||||||
// Implementation note: we MUST use an HTTP client that we're
|
// Implementation note: we MUST use an HTTP client that we're
|
||||||
// sure IS NOT using any proxy. To this end, we construct a
|
// sure IS NOT using any proxy. To this end, we construct a
|
||||||
// client ourself that we know is not proxied.
|
// client ourself that we know is not proxied.
|
||||||
dialer := netxlite.NewDialerWithResolver(c.Logger, c.Resolver)
|
txp := netxlite.NewHTTPTransportWithResolver(c.Logger, c.Resolver)
|
||||||
handshaker := netxlite.NewTLSHandshakerStdlib(c.Logger)
|
|
||||||
tlsDialer := netxlite.NewTLSDialer(dialer, handshaker)
|
|
||||||
txp := netxlite.NewHTTPTransport(c.Logger, dialer, tlsDialer)
|
|
||||||
clnt := &http.Client{Transport: txp}
|
clnt := &http.Client{Transport: txp}
|
||||||
defer clnt.CloseIdleConnections()
|
defer clnt.CloseIdleConnections()
|
||||||
ip, err := fn(ctx, clnt, c.Logger, c.UserAgent)
|
ip, err := fn(ctx, clnt, c.Logger, c.UserAgent)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user