support nil cfg

master
fangdingjun 6 years ago
parent 714e73abf1
commit a1577f80df

@ -41,6 +41,14 @@ type Conn struct {
// the Conn.Run have already called, should not call it again // the Conn.Run have already called, should not call it again
func Dial(network, addr string, cfg *tls.Config) (*Conn, error) { func Dial(network, addr string, cfg *tls.Config) (*Conn, error) {
nextProto := []string{"h2"} nextProto := []string{"h2"}
if cfg == nil {
_addr := addr
h, _, err := net.SplitHostPort(addr)
if err == nil {
_addr = h
}
cfg = &tls.Config{ServerName: _addr}
}
cfg.NextProtos = nextProto cfg.NextProtos = nextProto
conn, err := tls.Dial(network, addr, cfg) conn, err := tls.Dial(network, addr, cfg)
if err != nil { if err != nil {

Loading…
Cancel
Save