Skip to content

Commit

Permalink
cleanup: inline NewHTTPTransportWithLoggerResolverAndOptionalProxyURL
Browse files Browse the repository at this point in the history
This diff inlines the original implementation of the
netxlite.NewHTTPTransportWithLoggerResolverAndOptionalProxyURL
function inside the enginex package.

With this diff, we continue to partially detach the engine
networking from netxlite, to implement the beacons as described
by ooni/probe#2531.
  • Loading branch information
bassosimone committed Sep 14, 2023
1 parent 6e3088a commit 18594ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 66 deletions.
8 changes: 5 additions & 3 deletions internal/enginenetx/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ func NewHTTPTransport(
proxyURL *url.URL,
resolver model.Resolver,
) *HTTPTransport {
txp := netxlite.NewHTTPTransportWithLoggerResolverAndOptionalProxyURL(
logger, resolver, proxyURL,
)
dialer := netxlite.NewDialerWithResolver(logger, resolver)
dialer = netxlite.MaybeWrapWithProxyDialer(dialer, proxyURL)
handshaker := netxlite.NewTLSHandshakerStdlib(logger)
tlsDialer := netxlite.NewTLSDialer(dialer, handshaker)
txp := netxlite.NewHTTPTransport(logger, dialer, tlsDialer)
txp = bytecounter.WrapHTTPTransport(txp, counter)
return &HTTPTransport{txp}
}
20 changes: 0 additions & 20 deletions internal/netxlite/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"net"
"net/http"
"net/url"
"time"

oohttp "github.com/ooni/oohttp"
Expand Down Expand Up @@ -106,25 +105,6 @@ func (txp *httpTransportConnectionsCloser) CloseIdleConnections() {
txp.TLSDialer.CloseIdleConnections()
}

// NewHTTPTransportWithLoggerResolverAndOptionalProxyURL creates an HTTPTransport using
// the given logger and resolver and an optional proxy URL.
//
// Arguments:
//
// - logger is the MANDATORY logger;
//
// - resolver is the MANDATORY resolver;
//
// - purl is the OPTIONAL proxy URL.
func NewHTTPTransportWithLoggerResolverAndOptionalProxyURL(
logger model.DebugLogger, resolver model.Resolver, purl *url.URL) model.HTTPTransport {
dialer := NewDialerWithResolver(logger, resolver)
dialer = MaybeWrapWithProxyDialer(dialer, purl)
handshaker := NewTLSHandshakerStdlib(logger)
tlsDialer := NewTLSDialer(dialer, handshaker)
return NewHTTPTransport(logger, dialer, tlsDialer)
}

// NewHTTPTransportWithResolver creates a new HTTP transport using
// the stdlib for everything but the given resolver.
func NewHTTPTransportWithResolver(logger model.DebugLogger, reso model.Resolver) model.HTTPTransport {
Expand Down
43 changes: 0 additions & 43 deletions internal/netxlite/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"net"
"net/http"
"net/url"
"strings"
"sync/atomic"
"testing"
Expand All @@ -17,48 +16,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/model"
)

func TestNewHTTPTransportWithLoggerResolverAndOptionalProxyURL(t *testing.T) {
t.Run("without proxy URL", func(t *testing.T) {
logger := &mocks.Logger{}
resolver := &mocks.Resolver{}
txp := NewHTTPTransportWithLoggerResolverAndOptionalProxyURL(logger, resolver, nil)
txpLogger := txp.(*httpTransportLogger)
if txpLogger.Logger != logger {
t.Fatal("unexpected logger")
}
txpErrWrapper := txpLogger.HTTPTransport.(*httpTransportErrWrapper)
txpCc := txpErrWrapper.HTTPTransport.(*httpTransportConnectionsCloser)
dialer := txpCc.Dialer
dialerWithReadTimeout := dialer.(*httpDialerWithReadTimeout)
dialerLog := dialerWithReadTimeout.Dialer.(*dialerLogger)
dialerReso := dialerLog.Dialer.(*dialerResolverWithTracing)
if dialerReso.Resolver != resolver {
t.Fatal("invalid resolver")
}
})

t.Run("with proxy URL", func(t *testing.T) {
URL := &url.URL{}
logger := &mocks.Logger{}
resolver := &mocks.Resolver{}
txp := NewHTTPTransportWithLoggerResolverAndOptionalProxyURL(logger, resolver, URL)
txpLogger := txp.(*httpTransportLogger)
if txpLogger.Logger != logger {
t.Fatal("unexpected logger")
}
txpErrWrapper := txpLogger.HTTPTransport.(*httpTransportErrWrapper)
txpCc := txpErrWrapper.HTTPTransport.(*httpTransportConnectionsCloser)
dialer := txpCc.Dialer
dialerWithReadTimeout := dialer.(*httpDialerWithReadTimeout)
dialerProxy := dialerWithReadTimeout.Dialer.(*proxyDialer)
dialerLog := dialerProxy.Dialer.(*dialerLogger)
dialerReso := dialerLog.Dialer.(*dialerResolverWithTracing)
if dialerReso.Resolver != resolver {
t.Fatal("invalid resolver")
}
})
}

func TestNewHTTPTransportWithResolver(t *testing.T) {
expected := errors.New("mocked error")
reso := &mocks.Resolver{
Expand Down

0 comments on commit 18594ce

Please sign in to comment.