From 7044de8e4c7d3d869bc1e5518877b34283e58229 Mon Sep 17 00:00:00 2001 From: OrLojqrG <149913686+OrLojqrG@users.noreply.github.com> Date: Sun, 5 Nov 2023 12:44:33 +0000 Subject: [PATCH] Add support for the customization of the host domain in WebSocket (One of the V2Ray transport layers) --- docs/configuration/shared/v2ray-transport.md | 5 +++++ docs/configuration/shared/v2ray-transport.zh.md | 5 +++++ option/v2ray_transport.go | 1 + transport/v2raywebsocket/client.go | 6 +++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/configuration/shared/v2ray-transport.md b/docs/configuration/shared/v2ray-transport.md index 418ef28d..df6f9400 100644 --- a/docs/configuration/shared/v2ray-transport.md +++ b/docs/configuration/shared/v2ray-transport.md @@ -92,6 +92,7 @@ Specifies the timeout duration after sending a PING frame, within which a respon ```json { "type": "ws", + "host": "", "path": "", "headers": {}, "max_early_data": 0, @@ -99,6 +100,10 @@ Specifies the timeout duration after sending a PING frame, within which a respon } ``` +#### host + +Host domain. + #### path Path of HTTP request. diff --git a/docs/configuration/shared/v2ray-transport.zh.md b/docs/configuration/shared/v2ray-transport.zh.md index 2ea93562..31a618ba 100644 --- a/docs/configuration/shared/v2ray-transport.zh.md +++ b/docs/configuration/shared/v2ray-transport.zh.md @@ -91,6 +91,7 @@ HTTP 请求的额外标头 ```json { "type": "ws", + "host": "", "path": "", "headers": {}, "max_early_data": 0, @@ -98,6 +99,10 @@ HTTP 请求的额外标头 } ``` +#### host + +主机域名。 + #### path HTTP 请求路径 diff --git a/option/v2ray_transport.go b/option/v2ray_transport.go index 63af28a3..324d2c70 100644 --- a/option/v2ray_transport.go +++ b/option/v2ray_transport.go @@ -75,6 +75,7 @@ type V2RayHTTPOptions struct { } type V2RayWebsocketOptions struct { + Host string `json:"host,omitempty"` Path string `json:"path,omitempty"` Headers HTTPHeader `json:"headers,omitempty"` MaxEarlyData uint32 `json:"max_early_data,omitempty"` diff --git a/transport/v2raywebsocket/client.go b/transport/v2raywebsocket/client.go index 4fcc251a..ea1a549d 100644 --- a/transport/v2raywebsocket/client.go +++ b/transport/v2raywebsocket/client.go @@ -43,7 +43,11 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt } else { requestURL.Scheme = "wss" } - requestURL.Host = serverAddr.String() + if options.Host == "" { + requestURL.Host = serverAddr.String() + } else { + requestURL.Host = options.Host + } requestURL.Path = options.Path err := sHTTP.URLSetPath(&requestURL, options.Path) if err != nil {