1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
//go:build go1.15
// +build go1.15
package eventstreamtest
import (
"crypto/tls"
"net/http"
"net/http/httptest"
"golang.org/x/net/http2"
)
// /x/net/http2 is only available for the latest two versions of Go. Any Go
// version older than that cannot use the utility to configure the http2
// server.
func setupServer(server *httptest.Server, useH2 bool) *http.Client {
server.Config.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
}
clientTrans := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
if useH2 {
http2.ConfigureServer(server.Config, nil)
http2.ConfigureTransport(clientTrans)
server.Config.TLSConfig.NextProtos = []string{http2.NextProtoTLS}
clientTrans.TLSClientConfig.NextProtos = []string{http2.NextProtoTLS}
}
server.TLS = server.Config.TLSConfig
server.StartTLS()
return &http.Client{
Transport: clientTrans,
}
}
|