Browser Dialer: Potential optimized IP and non-standard port

Fixes https://github.com/2dust/v2rayNG/issues/5519#issuecomment-4335112057
This commit is contained in:
RPRX
2026-04-28 20:57:20 +00:00
committed by GitHub
parent b4f08981be
commit 1836b1c6e4
2 changed files with 31 additions and 6 deletions
+19 -6
View File
@@ -111,13 +111,20 @@ func dialWebSocket(ctx context.Context, dest net.Destination, streamSettings *in
}
}
host := dest.NetAddr()
if (protocol == "ws" && dest.Port == 80) || (protocol == "wss" && dest.Port == 443) {
host = dest.Address.String()
}
uri := protocol + "://" + host + wsSettings.GetNormalizedPath()
if browser_dialer.HasBrowserDialer() {
// For Browser Dialer's optimized IP and non-standard port
host := wsSettings.Host
if host == "" && tConfig.ServerName != "" {
host = tConfig.ServerName
}
if host == "" {
host = dest.Address.String()
}
if !(protocol == "ws" && dest.Port == 80) && !(protocol == "wss" && dest.Port == 443) {
host += ":" + dest.Port.String()
}
uri := protocol + "://" + host + wsSettings.GetNormalizedPath()
conn, err := browser_dialer.DialWS(uri, ed)
if err != nil {
return nil, err
@@ -126,6 +133,12 @@ func dialWebSocket(ctx context.Context, dest net.Destination, streamSettings *in
return NewConnection(conn, conn.RemoteAddr(), nil, wsSettings.HeartbeatPeriod), nil
}
host := dest.Address.String()
if !(protocol == "ws" && dest.Port == 80) && !(protocol == "wss" && dest.Port == 443) {
host += ":" + dest.Port.String()
}
uri := protocol + "://" + host + wsSettings.GetNormalizedPath()
header := wsSettings.GetRequestHeader()
// See dialer.DialContext()
header.Set("Host", wsSettings.Host)