diff --git a/README.md b/README.md index e2dff6a..0eb2966 100644 --- a/README.md +++ b/README.md @@ -155,8 +155,13 @@ Example: `CDNOriginHost` is the domain name of the _origin_ server (i.e. the server running Cloak) under `CDN` mode. This only has effect when `Transport` is set to `CDN`. If unset, it will default to the remote hostname supplied via the commandline argument (in standalone mode), or by Shadowsocks (in plugin mode). After a TLS session is established with -the CDN server, this domain name will be used in the HTTP request to ask the CDN server to establish a WebSocket -connection with this host. +the CDN server, this domain name will be used in the `Host` header of the HTTP request to ask the CDN server to +establish a WebSocket connection with this host. + +`CDNWsUrlPath` is the url path used to build websocket request sent under `CDN` mode, and also only has effect +when `Transport` is set to `CDN`. If unset, it will default to "/". This option is used to build the first line of the +HTTP request after a TLS session is extablished. It's mainly for a Cloak server behind a reverse proxy, while only +requests under specific url path are forwarded. `NumConn` is the amount of underlying TCP connections you want to use. The default of 4 should be appropriate for most people. Setting it too high will hinder the performance. Setting it to 0 will disable connection multiplexing and each diff --git a/internal/client/state.go b/internal/client/state.go index cdd29a1..dfda038 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -37,6 +37,7 @@ type RawConfig struct { BrowserSig string // nullable Transport string // nullable CDNOriginHost string // nullable + CDNWsUrlPath string // nullable StreamTimeout int // nullable KeepAlive int // nullable } @@ -225,10 +226,13 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca } else { cdnDomainPort = net.JoinHostPort(raw.CDNOriginHost, raw.RemotePort) } + if raw.CDNWsUrlPath == "" { + raw.CDNWsUrlPath = "/" + } remote.TransportMaker = func() Transport { return &WSOverTLS{ - cdnDomainPort: cdnDomainPort, + wsUrl: "ws://" + cdnDomainPort + raw.CDNWsUrlPath, } } case "direct": diff --git a/internal/client/websocket.go b/internal/client/websocket.go index 4e3532e..bddee23 100644 --- a/internal/client/websocket.go +++ b/internal/client/websocket.go @@ -15,7 +15,7 @@ import ( type WSOverTLS struct { *common.WebSocketConn - cdnDomainPort string + wsUrl string } func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error) { @@ -41,7 +41,7 @@ func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey return } - u, err := url.Parse("ws://" + ws.cdnDomainPort) + u, err := url.Parse(ws.wsUrl) if err != nil { return sessionKey, fmt.Errorf("failed to parse ws url: %v", err) }