1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 01:40:44 +00:00

normalized path in websocket

This commit is contained in:
Darien Raymond 2017-02-10 11:47:53 +01:00
parent 5e7fb6d0dd
commit 1aeab3dd96
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 13 additions and 2 deletions

View File

@ -12,6 +12,17 @@ func (c *Config) IsConnectionReuse() bool {
return c.ConnectionReuse.Enable
}
func (c *Config) GetNormailzedPath() string {
path := c.Path
if len(path) == 0 {
return "/"
}
if path[0] != '/' {
return "/" + path
}
return path
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} {
return new(Config)

View File

@ -74,7 +74,7 @@ func wsDial(ctx context.Context, dest v2net.Destination) (net.Conn, error) {
if (protocol == "ws" && dest.Port == 80) || (protocol == "wss" && dest.Port == 443) {
host = dest.Address.String()
}
uri := protocol + "://" + host + "/" + wsSettings.Path
uri := protocol + "://" + host + wsSettings.GetNormailzedPath()
conn, resp, err := dialer.Dial(uri, nil)
if err != nil {

View File

@ -108,7 +108,7 @@ func (ln *Listener) listenws(address v2net.Address, port v2net.Port) error {
go func() {
http.Serve(listener, &requestHandler{
path: "/" + ln.config.Path,
path: "/" + ln.config.GetNormailzedPath(),
conns: ln.awaitingConns,
})
}()