c1b06a2d09
This diff has been extracted and adapted from 8848c8c516
The reason to prefer composition over embedding is that we want the
build to break if we add new methods to interfaces we define. If the build
does not break, we may forget about wrapping methods we should
actually be wrapping. I noticed this issue inside netxlite when I was working
on websteps-illustrated and I added support for NS and PTR queries.
See https://github.com/ooni/probe/issues/2096
While there, perform comprehensive netxlite code review
and apply minor changes and improve the docs.
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package netxlite
|
|
|
|
//
|
|
// HTTP3 code
|
|
//
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/lucas-clemente/quic-go/http3"
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
// http3RoundTripper is the abstract type of quic-go/http3.RoundTripper.
|
|
type http3RoundTripper interface {
|
|
http.RoundTripper
|
|
io.Closer
|
|
}
|
|
|
|
// http3Transport is an HTTPTransport using the http3 protocol.
|
|
type http3Transport struct {
|
|
child http3RoundTripper
|
|
dialer model.QUICDialer
|
|
}
|
|
|
|
var _ model.HTTPTransport = &http3Transport{}
|
|
|
|
// Network implements HTTPTransport.Network.
|
|
func (txp *http3Transport) Network() string {
|
|
return "quic"
|
|
}
|
|
|
|
// RoundTrip implements HTTPTransport.RoundTrip.
|
|
func (txp *http3Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
return txp.child.RoundTrip(req)
|
|
}
|
|
|
|
// CloseIdleConnections implements HTTPTransport.CloseIdleConnections.
|
|
func (txp *http3Transport) CloseIdleConnections() {
|
|
txp.child.Close()
|
|
txp.dialer.CloseIdleConnections()
|
|
}
|
|
|
|
// NewHTTP3Transport creates a new HTTPTransport using http3. The
|
|
// dialer argument MUST NOT be nil. If the tlsConfig argument is nil,
|
|
// then the code will use the default TLS configuration.
|
|
func NewHTTP3Transport(
|
|
logger model.DebugLogger, dialer model.QUICDialer, tlsConfig *tls.Config) model.HTTPTransport {
|
|
return &httpTransportLogger{
|
|
HTTPTransport: &http3Transport{
|
|
child: &http3.RoundTripper{
|
|
Dial: dialer.DialContext,
|
|
// 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,
|
|
},
|
|
Logger: logger,
|
|
}
|
|
}
|