From 94368f43eb531a33f6b85f9d25c21a83597d495e Mon Sep 17 00:00:00 2001 From: MetaCubeX Date: Fri, 10 Jun 2022 03:15:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Vmess=20URI=20Scheme=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/outbound/vmess.go | 9 ++++----- common/convert/converter.go | 17 +++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 0d65b31e..1ad5036f 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -109,8 +109,10 @@ func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { wsOpts.TLSConfig.ServerName = host } } else { - wsOpts.Headers.Set("Host", convert.RandHost()) - convert.SetUserAgent(wsOpts.Headers) + if host := wsOpts.Headers.Get("Host"); host == "" { + wsOpts.Headers.Set("Host", convert.RandHost()) + convert.SetUserAgent(wsOpts.Headers) + } } c, err = vmess.StreamWebsocketConn(c, wsOpts) case "http": @@ -130,9 +132,6 @@ func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { if err != nil { return nil, err } - } else { - http.Header(v.option.HTTPOpts.Headers).Set("Host", convert.RandHost()) - convert.SetUserAgent(v.option.HTTPOpts.Headers) } host, _, _ := net.SplitHostPort(v.addr) diff --git a/common/convert/converter.go b/common/convert/converter.go index 7a96743e..23fdf652 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -244,9 +244,13 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { vmess["udp"] = true vmess["skip-cert-verify"] = false + if values["cipher"] != nil && values["cipher"] != "" { + vmess["cipher"] = values["cipher"] + } + sni := values["sni"] if sni != "" { - vmess["sni"] = sni + vmess["servername"] = sni } host := values["host"] @@ -256,7 +260,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { tls := strings.ToLower(values["tls"].(string)) if tls != "" && tls != "0" && tls != "null" { - if host != nil { + if host != "" || host != nil { vmess["servername"] = host } vmess["tls"] = true @@ -267,7 +271,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { headers := make(map[string]any) httpOpts := make(map[string]any) - //headers["Host"] = RandHost() + headers["Host"] = RandHost() headers["User-Agent"] = RandUserAgent() httpOpts["method"] = values["method"] httpOpts["path"] = values["path"] @@ -289,11 +293,12 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { case "ws": headers := make(map[string]any) wsOpts := make(map[string]any) - - headers["Host"] = RandHost() + if host != "" && host != nil { + headers["Host"] = host + } headers["User-Agent"] = RandUserAgent() - if values["path"] != nil { + if values["path"] != nil || values["path"] != "" { wsOpts["path"] = values["path"] } wsOpts["headers"] = headers