fix wss bug
This commit is contained in:
parent
f7c8c40081
commit
986b27475f
4
conn.go
4
conn.go
@ -440,13 +440,13 @@ func forward(conn net.Conn, arg Args) (net.Conn, error) {
|
||||
|
||||
switch arg.Transport {
|
||||
case "ws": // websocket connection
|
||||
conn, err = wsClient(conn, arg.Addr)
|
||||
conn, err = wsClient("ws", conn, arg.Addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "wss": // websocket security
|
||||
tlsUsed = true
|
||||
conn, err = wssClient(conn, arg.Addr)
|
||||
conn, err = wsClient("wss", conn, arg.Addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
28
ws.go
28
ws.go
@ -17,24 +17,18 @@ type wsConn struct {
|
||||
rb []byte
|
||||
}
|
||||
|
||||
func wsClient(conn net.Conn, host string) (*wsConn, error) {
|
||||
c, resp, err := websocket.NewClient(conn, &url.URL{Scheme: "ws", Host: host, Path: "/ws"}, nil, 4096, 4096)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func wsClient(scheme string, conn net.Conn, host string) (*wsConn, error) {
|
||||
dialer := websocket.Dialer{
|
||||
ReadBufferSize: 4096,
|
||||
WriteBufferSize: 4096,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
HandshakeTimeout: time.Second * 90,
|
||||
NetDial: func(net, addr string) (net.Conn, error) {
|
||||
return conn, nil
|
||||
},
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
return &wsConn{conn: c}, nil
|
||||
}
|
||||
|
||||
func wssClient(conn net.Conn, host string) (*wsConn, error) {
|
||||
tlsConn := tls.Client(conn, &tls.Config{InsecureSkipVerify: true})
|
||||
if err := tlsConn.Handshake(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conn = tlsConn
|
||||
|
||||
c, resp, err := websocket.NewClient(conn, &url.URL{Scheme: "wss", Host: host, Path: "/ws"}, nil, 4096, 4096)
|
||||
u := url.URL{Scheme: scheme, Host: host, Path: "/ws"}
|
||||
c, resp, err := dialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user