refactor: move base http3 transport into netxlite (#412)
This diff is part of https://github.com/ooni/probe/issues/1505. You will notice that I have not adapted all the (great) tests we had previously. They should live at another layer, and namely the one that deals with performing measurements. When I'm refactoring such a layer I'll ensure those tests that I have not adapted here are reintroduced into the tree.
This commit is contained in:
parent
527e1a0707
commit
4dc2907472
6 changed files with 87 additions and 196 deletions
|
|
@ -1,43 +1,10 @@
|
|||
package httptransport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/http3"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
// QUICWrapperDialer is a QUICDialer that wraps a ContextDialer
|
||||
// This is necessary because the http3 RoundTripper does not support a DialContext method.
|
||||
type QUICWrapperDialer struct {
|
||||
Dialer quicdialer.ContextDialer
|
||||
}
|
||||
|
||||
// Dial implements QUICDialer.Dial
|
||||
func (d QUICWrapperDialer) Dial(network, host string, tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) {
|
||||
return d.Dialer.DialContext(context.Background(), network, host, tlsCfg, cfg)
|
||||
}
|
||||
|
||||
// HTTP3Transport is a httptransport.RoundTripper using the http3 protocol.
|
||||
type HTTP3Transport struct {
|
||||
http3.RoundTripper
|
||||
}
|
||||
|
||||
// CloseIdleConnections closes all the connections opened by this transport.
|
||||
func (t *HTTP3Transport) CloseIdleConnections() {
|
||||
t.RoundTripper.Close()
|
||||
}
|
||||
|
||||
// NewHTTP3Transport creates a new HTTP3Transport instance.
|
||||
func NewHTTP3Transport(config Config) RoundTripper {
|
||||
txp := &HTTP3Transport{}
|
||||
txp.QuicConfig = &quic.Config{}
|
||||
txp.TLSClientConfig = config.TLSConfig
|
||||
txp.Dial = config.QUICDialer.Dial
|
||||
return txp
|
||||
return netxlite.NewHTTP3Transport(config.QUICDialer, config.TLSConfig)
|
||||
}
|
||||
|
||||
var _ RoundTripper = &http.Transport{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue