feat: wss support (#2194)

This commit is contained in:
tudyzhb 2021-10-04 23:35:03 +08:00
parent 0cee1877e3
commit 91c9011736
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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