26 lines
536 B
Go
26 lines
536 B
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net"
|
|
"net/http"
|
|
|
|
"golang.org/x/net/http2"
|
|
)
|
|
|
|
func NewH2cHTTPClient() *http.Client {
|
|
return &http.Client{
|
|
Transport: &http2.Transport{
|
|
AllowHTTP: true,
|
|
DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
|
|
// If you're also using this client for non-h2c traffic, you may want
|
|
// to delegate to tls.Dial if the network isn't TCP or the addr isn't
|
|
// in an allowlist.
|
|
|
|
return net.Dial(network, addr)
|
|
},
|
|
},
|
|
}
|
|
}
|