feat: wss support (#2194)
This commit is contained in:
parent
0cee1877e3
commit
91c9011736
@ -21,8 +21,10 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -229,6 +231,17 @@ func (svr *Service) login() (conn net.Conn, session *fmux.Session, err error) {
|
||||
}
|
||||
|
||||
address := net.JoinHostPort(svr.cfg.ServerAddr, strconv.Itoa(svr.cfg.ServerPort))
|
||||
if svr.cfg.Protocol == "websocket" {
|
||||
// compatible: construct the websocket server addr
|
||||
address = "ws://" + address
|
||||
if _url, _err := url.Parse(svr.cfg.ServerAddr); _err == nil && len(_url.Scheme) > 0 {
|
||||
// support the cfg.ServerAddr parameter with the URL format, i.e. wss://domain/path/
|
||||
address = svr.cfg.ServerAddr
|
||||
}
|
||||
// add the frp websocket special path
|
||||
address = strings.TrimRight(address, "/") + frpNet.FrpWebsocketPath
|
||||
}
|
||||
|
||||
conn, err = frpNet.ConnectServerByProxyWithTLS(svr.cfg.HTTPProxy, svr.cfg.Protocol, address, tlsConfig, svr.cfg.DisableCustomTLSFirstByte)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -78,9 +78,8 @@ func (p *WebsocketListener) Addr() net.Addr {
|
||||
return p.ln.Addr()
|
||||
}
|
||||
|
||||
// addr: domain:port
|
||||
// addr: url
|
||||
func ConnectWebsocketServer(addr string) (net.Conn, error) {
|
||||
addr = "ws://" + addr + FrpWebsocketPath
|
||||
uri, err := url.Parse(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user