fix(netxlite): http3 transport needs logging by default (#492)

Adapt other places where it was not using a logger to either choose
a reasonable logger or disable logging for backwards compat.

See https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso
2021-09-08 20:49:01 +02:00
committed by GitHub
parent 18b2eb37ff
commit e68adec9a5
5 changed files with 35 additions and 16 deletions
+14 -11
View File
@@ -53,17 +53,20 @@ func (txp *http3Transport) CloseIdleConnections() {
// dialer argument MUST NOT be nil. If the tlsConfig argument is nil,
// then the code will use the default TLS configuration.
func NewHTTP3Transport(
dialer QUICDialer, tlsConfig *tls.Config) HTTPTransport {
return &http3Transport{
child: &http3.RoundTripper{
Dial: (&http3Dialer{dialer}).dial,
// The following (1) reduces the number of headers that Go will
// automatically send for us and (2) ensures that we always receive
// back the true headers, such as Content-Length. This change is
// functional to OONI's goal of observing the network.
DisableCompression: true,
TLSClientConfig: tlsConfig,
logger Logger, dialer QUICDialer, tlsConfig *tls.Config) HTTPTransport {
return &httpTransportLogger{
HTTPTransport: &http3Transport{
child: &http3.RoundTripper{
Dial: (&http3Dialer{dialer}).dial,
// The following (1) reduces the number of headers that Go will
// automatically send for us and (2) ensures that we always receive
// back the true headers, such as Content-Length. This change is
// functional to OONI's goal of observing the network.
DisableCompression: true,
TLSClientConfig: tlsConfig,
},
dialer: dialer,
},
dialer: dialer,
Logger: logger,
}
}
+7 -2
View File
@@ -7,6 +7,7 @@ import (
"net/http"
"testing"
"github.com/apex/log"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
@@ -80,8 +81,12 @@ func TestNewHTTP3Transport(t *testing.T) {
t.Run("creates the correct type chain", func(t *testing.T) {
qd := &mocks.QUICDialer{}
config := &tls.Config{}
txp := NewHTTP3Transport(qd, config)
h3txp := txp.(*http3Transport)
txp := NewHTTP3Transport(log.Log, qd, config)
logger := txp.(*httpTransportLogger)
if logger.Logger != log.Log {
t.Fatal("invalid logger")
}
h3txp := logger.HTTPTransport.(*http3Transport)
if h3txp.dialer != qd {
t.Fatal("invalid dialer")
}
+1 -1
View File
@@ -42,7 +42,7 @@ func TestHTTP3Transport(t *testing.T) {
log.Log,
netxlite.NewResolverSystem(log.Log),
)
txp := netxlite.NewHTTP3Transport(d, &tls.Config{})
txp := netxlite.NewHTTP3Transport(log.Log, d, &tls.Config{})
client := &http.Client{Transport: txp}
resp, err := client.Get("https://www.google.com/robots.txt")
if err != nil {