diff --git a/README.md b/README.md index e54fd617..e6ad5115 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ - - + + - - + +

diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index bc47c675..8f63533e 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -91,17 +91,16 @@ func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { wsOpts := &vmess.WebsocketConfig{ Host: host, Port: port, + Headers: http.Header{}, Path: v.option.WSOpts.Path, MaxEarlyData: v.option.WSOpts.MaxEarlyData, EarlyDataHeaderName: v.option.WSOpts.EarlyDataHeaderName, } if len(v.option.WSOpts.Headers) != 0 { - header := http.Header{} for key, value := range v.option.WSOpts.Headers { - header.Add(key, value) + wsOpts.Headers.Add(key, value) } - wsOpts.Headers = header } if v.option.TLS { @@ -138,9 +137,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/adapter/parser.go b/adapter/parser.go index 444edd1a..1c4bfa39 100644 --- a/adapter/parser.go +++ b/adapter/parser.go @@ -57,8 +57,9 @@ func ParseProxy(mapping map[string]any, forceCertVerify bool) (C.Proxy, error) { case "vmess": vmessOption := &outbound.VmessOption{ HTTPOpts: outbound.HTTPOptions{ - Method: "GET", - Path: []string{"/"}, + Method: "GET", + Path: []string{"/"}, + Headers: make(map[string][]string), }, } err = decoder.Decode(mapping, vmessOption) diff --git a/adapter/provider/vehicle.go b/adapter/provider/vehicle.go index 1d5fe5ba..f48d60b5 100644 --- a/adapter/provider/vehicle.go +++ b/adapter/provider/vehicle.go @@ -11,7 +11,6 @@ import ( "github.com/Dreamacro/clash/common/convert" "github.com/Dreamacro/clash/component/dialer" - C "github.com/Dreamacro/clash/constant" types "github.com/Dreamacro/clash/constant/provider" ) @@ -82,13 +81,11 @@ func (h *HTTPVehicle) Read() ([]byte, error) { IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, - DialContext: func(ctx context.Context, network, address string) (conn net.Conn, err error) { - conn, err = dialer.DialContext(ctx, network, address) // with direct - if err != nil { - // fallback to tun if tun enabled - conn, err = (&net.Dialer{Timeout: C.DefaultTCPTimeout}).Dial(network, address) + DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { + if req.URL.Scheme == "https" { + return (&net.Dialer{}).DialContext(ctx, network, address) // forward to tun if tun enabled } - return + return dialer.DialContext(ctx, network, address, dialer.WithDirect()) // with direct }, } diff --git a/common/convert/converter.go b/common/convert/converter.go index cdd86789..f03674b7 100644 --- a/common/convert/converter.go +++ b/common/convert/converter.go @@ -21,21 +21,24 @@ func DecodeBase64(buf []byte) ([]byte, error) { return dBuf[:n], nil } -// DecodeBase64StringToString decode base64 string to string -func DecodeBase64StringToString(s string) (string, error) { - dBuf, err := enc.DecodeString(s) +func DecodeRawBase64(buf []byte) ([]byte, error) { + dBuf := make([]byte, base64.RawStdEncoding.DecodedLen(len(buf))) + n, err := base64.RawStdEncoding.Decode(dBuf, buf) if err != nil { - return "", err + return nil, err } - return string(dBuf), nil + return dBuf[:n], nil } // ConvertsV2Ray convert V2Ray subscribe proxies data to clash proxies config func ConvertsV2Ray(buf []byte) ([]map[string]any, error) { data, err := DecodeBase64(buf) if err != nil { - data = buf + data, err = DecodeRawBase64(buf) + if err != nil { + data = buf + } } arr := strings.Split(string(data), "\n") diff --git a/rule/geosite.go b/rule/geosite.go index 22f39887..a98cee23 100644 --- a/rule/geosite.go +++ b/rule/geosite.go @@ -51,11 +51,11 @@ func NewGEOSITE(country string, adapter string) (*GEOSITE, error) { return nil, fmt.Errorf("load GeoSite data error, %s", err.Error()) } - cont := fmt.Sprintf("%d", recordsCount) + count := fmt.Sprintf("%d", recordsCount) if recordsCount == 0 { - cont = "from cache" + count = "from cache" } - log.Infoln("Start initial GeoSite rule %s => %s, records: %s", country, adapter, cont) + log.Infoln("Start initial GeoSite rule %s => %s, records: %s", country, adapter, count) geoSite := &GEOSITE{ Base: &Base{},