From 4cc9ebb5e82d412762b3ce966bed6140abf6ad9e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 22 Dec 2023 18:28:47 +0330 Subject: [PATCH] Fix v2ray transport's client path && Update the docs --- docs/configuration/shared/v2ray-transport.md | 6 +++--- docs/configuration/shared/v2ray-transport.zh.md | 6 +++--- transport/v2rayhttp/client.go | 4 ++++ transport/v2rayhttpupgrade/client.go | 3 +++ transport/v2raywebsocket/client.go | 3 +++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/configuration/shared/v2ray-transport.md b/docs/configuration/shared/v2ray-transport.md index d29572f6..6a772190 100644 --- a/docs/configuration/shared/v2ray-transport.md +++ b/docs/configuration/shared/v2ray-transport.md @@ -55,7 +55,7 @@ The client will choose randomly and the server will verify if not empty. Path of HTTP request. -The server will verify if not empty. +`/` will be used if empty. #### method @@ -103,7 +103,7 @@ Specifies the timeout duration after sending a PING frame, within which a respon Path of HTTP request. -The server will verify if not empty. +`/` will be used if empty. #### headers @@ -203,7 +203,7 @@ The server will verify if not empty. Path of HTTP request. -The server will verify if not empty. +`/` will be used if empty. #### headers diff --git a/docs/configuration/shared/v2ray-transport.zh.md b/docs/configuration/shared/v2ray-transport.zh.md index d0b4775d..4601e26a 100644 --- a/docs/configuration/shared/v2ray-transport.zh.md +++ b/docs/configuration/shared/v2ray-transport.zh.md @@ -54,7 +54,7 @@ V2Ray Transport 是 v2ray 发明的一组私有协议,并污染了其他协议 HTTP 请求路径 -默认服务器将验证。 +默认 `/`。 #### method @@ -102,7 +102,7 @@ HTTP 请求的额外标头 HTTP 请求路径 -默认服务器将验证。 +默认 `/`。 #### headers @@ -202,7 +202,7 @@ gRPC 服务名称。 HTTP 请求路径 -默认服务器将验证。 +默认 `/`。 #### headers diff --git a/transport/v2rayhttp/client.go b/transport/v2rayhttp/client.go index 44c135ef..9a446c62 100644 --- a/transport/v2rayhttp/client.go +++ b/transport/v2rayhttp/client.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "net/url" + "strings" "time" "github.com/sagernet/sing-box/adapter" @@ -77,6 +78,9 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt } else { uri.Scheme = "https" } + if !strings.Contains(options.Path, "/") { + options.Path = "/" + options.Path + } uri.Host = serverAddr.String() uri.Path = options.Path err := sHTTP.URLSetPath(&uri, options.Path) diff --git a/transport/v2rayhttpupgrade/client.go b/transport/v2rayhttpupgrade/client.go index c10e1b8f..a2513ba9 100644 --- a/transport/v2rayhttpupgrade/client.go +++ b/transport/v2rayhttpupgrade/client.go @@ -50,6 +50,9 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt } else { requestURL.Scheme = "https" } + if !strings.Contains(options.Path, "/") { + options.Path = "/" + options.Path + } requestURL.Host = serverAddr.String() requestURL.Path = options.Path err := sHTTP.URLSetPath(&requestURL, options.Path) diff --git a/transport/v2raywebsocket/client.go b/transport/v2raywebsocket/client.go index 7fda40cc..2716f22c 100644 --- a/transport/v2raywebsocket/client.go +++ b/transport/v2raywebsocket/client.go @@ -46,6 +46,9 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt } else { requestURL.Scheme = "wss" } + if !strings.Contains(options.Path, "/") { + options.Path = "/" + options.Path + } requestURL.Host = serverAddr.String() requestURL.Path = options.Path err := sHTTP.URLSetPath(&requestURL, options.Path)