implement a Dial function for the h2quic.RoundTripper

If Dial is set, it will be used for dialing new QUIC connections. If it
is nil, quic.DialAddr will be used.
This commit is contained in:
Marten Seemann
2018-01-15 12:18:47 +07:00
parent 15bcc2579f
commit ef56cae9dc
4 changed files with 78 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ type client struct {
hostname string
handshakeErr error
dialOnce sync.Once
dialer func(network, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.Session, error)
session quic.Session
headerStream quic.Stream
@@ -60,6 +61,7 @@ func newClient(
tlsConfig *tls.Config,
opts *roundTripperOpts,
quicConfig *quic.Config,
dialer func(network, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.Session, error),
) *client {
config := defaultQuicConfig
if quicConfig != nil {
@@ -72,13 +74,18 @@ func newClient(
config: config,
opts: opts,
headerErrored: make(chan struct{}),
dialer: dialer,
}
}
// dial dials the connection
func (c *client) dial() error {
var err error
c.session, err = dialAddr(c.hostname, c.tlsConf, c.config)
if c.dialer != nil {
c.session, err = c.dialer("udp", c.hostname, c.tlsConf, c.config)
} else {
c.session, err = dialAddr(c.hostname, c.tlsConf, c.config)
}
if err != nil {
return err
}