make the dependency-injected dialAddr in h2quic.client a global variable

It's only used for testing, so there's no need to have in each
h2quic.client instance.
This commit is contained in:
Marten Seemann
2017-07-08 16:40:53 +08:00
parent d94b57fe29
commit cb81a95ceb
3 changed files with 58 additions and 19 deletions

View File

@@ -24,14 +24,15 @@ type roundTripperOpts struct {
DisableCompression bool
}
var dialAddr = quic.DialAddr
// client is a HTTP2 client doing QUIC requests
type client struct {
mutex sync.RWMutex
dialAddr func(hostname string, tlsConf *tls.Config, config *quic.Config) (quic.Session, error)
tlsConf *tls.Config
config *quic.Config
opts *roundTripperOpts
tlsConf *tls.Config
config *quic.Config
opts *roundTripperOpts
hostname string
encryptionLevel protocol.EncryptionLevel
@@ -52,7 +53,6 @@ var _ http.RoundTripper = &client{}
// newClient creates a new client
func newClient(tlsConfig *tls.Config, hostname string, opts *roundTripperOpts) *client {
return &client{
dialAddr: quic.DialAddr,
hostname: authorityAddr("https", hostname),
responses: make(map[protocol.StreamID]chan *http.Response),
encryptionLevel: protocol.EncryptionUnencrypted,
@@ -69,7 +69,7 @@ func newClient(tlsConfig *tls.Config, hostname string, opts *roundTripperOpts) *
// dial dials the connection
func (c *client) dial() error {
var err error
c.session, err = c.dialAddr(c.hostname, c.tlsConf, c.config)
c.session, err = dialAddr(c.hostname, c.tlsConf, c.config)
if err != nil {
return err
}