From c622f3a8d608622e94f9119a13dc8d41ebc9bd09 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 29 Nov 2018 12:10:33 +0000 Subject: [PATCH] Force http2 usage of broker client --- broker/http_broker.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/broker/http_broker.go b/broker/http_broker.go index 3ff42aa2..dad8ed6c 100644 --- a/broker/http_broker.go +++ b/broker/http_broker.go @@ -27,6 +27,7 @@ import ( maddr "github.com/micro/util/go/lib/addr" mnet "github.com/micro/util/go/lib/net" mls "github.com/micro/util/go/lib/tls" + "golang.org/x/net/http2" ) // HTTP Broker is a point to point async broker @@ -78,6 +79,10 @@ func newTransport(config *tls.Config) *http.Transport { } } + dialTLS := func(network string, addr string) (net.Conn, error) { + return tls.Dial(network, addr, config) + } + t := &http.Transport{ Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ @@ -85,11 +90,15 @@ func newTransport(config *tls.Config) *http.Transport { KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: config, + DialTLS: dialTLS, } runtime.SetFinalizer(&t, func(tr **http.Transport) { (*tr).CloseIdleConnections() }) + + // setup http2 + http2.ConfigureTransport(t) + return t } @@ -430,6 +439,13 @@ func (h *httpBroker) Init(opts ...Option) error { // set registry h.r = rcache.New(reg) + // reconfigure tls config + if c := h.opts.TLSConfig; c != nil { + h.c = &http.Client{ + Transport: newTransport(c), + } + } + return nil }