1
0
mirror of https://github.com/fumiama/terasu-cloudflared.git synced 2026-06-05 00:50:24 +08:00
Files
terasu-cloudflared/vendor/golang.org/x/net/websocket/dial.go
2025-12-21 16:51:38 +08:00

44 lines
1000 B
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package websocket
import (
"context"
"crypto/tls"
"net"
"time"
"github.com/fumiama/terasu"
)
func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
switch config.Location.Scheme {
case "ws":
conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
case "wss":
var rawConn net.Conn
rawConn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
if err == nil {
tlsCn := tls.Client(terasu.NewConn(rawConn), config.TlsConfig)
if deadline, ok := ctx.Deadline(); ok {
rawConn.SetDeadline(deadline)
}
err = tlsCn.Handshake()
if _, ok := ctx.Deadline(); ok {
rawConn.SetDeadline(time.Time{})
}
if err != nil {
rawConn.Close()
} else {
conn = tlsCn
}
}
default:
err = ErrBadScheme
}
return
}