Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support wss protocol #1919

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/frpc/sub/root.go
Expand Up @@ -86,7 +86,7 @@ func init() {
func RegisterCommonFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address")
cmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user")
cmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket")
cmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket or wss")
cmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token")
cmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level")
cmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path")
Expand Down
2 changes: 1 addition & 1 deletion conf/frpc_full.ini
Expand Up @@ -46,7 +46,7 @@ user = your_name
login_fail_exit = true

# communication protocol used to connect to server
# now it supports tcp and kcp and websocket, default is tcp
# now it supports tcp, kcp, websocket and wss, default is tcp
protocol = tcp

# if tls_enable is true, frpc will connect frps by tls
Expand Down
2 changes: 1 addition & 1 deletion models/config/client_common.go
Expand Up @@ -267,7 +267,7 @@ func UnmarshalClientConfFromIni(content string) (cfg ClientCommonConf, err error

if tmpStr, ok = conf.Get("common", "protocol"); ok {
// Now it only support tcp and kcp and websocket.
if tmpStr != "tcp" && tmpStr != "kcp" && tmpStr != "websocket" {
if tmpStr != "tcp" && tmpStr != "kcp" && tmpStr != "websocket" && tmpStr != "wss" {
err = fmt.Errorf("Parse conf error: invalid protocol")
return
}
Expand Down
4 changes: 3 additions & 1 deletion utils/net/conn.go
Expand Up @@ -221,7 +221,9 @@ func ConnectServerByProxy(proxyURL string, protocol string, addr string) (c net.
// http proxy is not supported for kcp
return ConnectServer(protocol, addr)
case "websocket":
return ConnectWebsocketServer(addr)
return ConnectWebsocketServer(addr, false)
case "wss":
return ConnectWebsocketServer(addr, true)
default:
return nil, fmt.Errorf("unsupport protocol: %s", protocol)
}
Expand Down
18 changes: 15 additions & 3 deletions utils/net/websocket.go
Expand Up @@ -79,14 +79,26 @@ func (p *WebsocketListener) Addr() net.Addr {
}

// addr: domain:port
func ConnectWebsocketServer(addr string) (net.Conn, error) {
addr = "ws://" + addr + FrpWebsocketPath
func ConnectWebsocketServer(addr string, isSecure bool) (net.Conn, error) {

if isSecure {
addr = "wss://" + addr + FrpWebsocketPath
} else {
addr = "ws://" + addr + FrpWebsocketPath
}

uri, err := url.Parse(addr)
if err != nil {
return nil, err
}

origin := "http://" + uri.Host
var origin string
if isSecure {
origin = "https://" + uri.Host
} else {
origin = "http://" + uri.Host
}

cfg, err := websocket.NewConfig(addr, origin)
if err != nil {
return nil, err
Expand Down