diff --git a/component/outbound/dialer/v2ray/v2ray.go b/component/outbound/dialer/v2ray/v2ray.go index 00b4f2a00..8987ad090 100644 --- a/component/outbound/dialer/v2ray/v2ray.go +++ b/component/outbound/dialer/v2ray/v2ray.go @@ -16,6 +16,7 @@ import ( "github.com/mzz2017/softwind/netproxy" "github.com/mzz2017/softwind/protocol" "github.com/mzz2017/softwind/protocol/direct" + "github.com/mzz2017/softwind/protocol/http" "github.com/mzz2017/softwind/transport/grpc" ) @@ -141,6 +142,33 @@ func (s *V2Ray) Dialer(option *dialer.GlobalOption, iOption dialer.InstanceOptio ServerName: sni, AllowInsecure: s.AllowInsecure, } + case "http", "http2", "h2": + sni := s.SNI + if sni == "" { + sni = s.Add + } + scheme := "http" + if s.TLS == "tls" { + scheme = "https" + } + u := url.URL{ + Scheme: scheme, + Host: net.JoinHostPort(s.Add, s.Port), + Path: s.Path, + RawQuery: url.Values{ + "sni": []string{sni}, + "allowInsecure": []string{common.BoolToString(s.AllowInsecure)}, + "tlsImplementation": []string{option.TlsImplementation}, + "utlsImitate": []string{option.UtlsImitate}, + "host": []string{s.Host}, + "alpn": []string{s.Alpn}, + "transport": []string{"1"}, + }.Encode(), + } + d, err = http.NewHTTPProxy(&u, direct.SymmetricDirect) + if err != nil { + return nil, err + } default: return nil, fmt.Errorf("%w: network: %v", dialer.UnexpectedFieldErr, s.Net) } diff --git a/docs/en/proxy-protocols.md b/docs/en/proxy-protocols.md index 0ee261a93..d54dfb38e 100644 --- a/docs/en/proxy-protocols.md +++ b/docs/en/proxy-protocols.md @@ -12,6 +12,7 @@ - [x] WS - [x] TLS - [x] gRPC + - [x] h2 - [x] Shadowsocks - [x] AEAD Ciphers - [x] Stream Ciphers diff --git a/go.mod b/go.mod index 7446ada8f..aee7e87de 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/miekg/dns v1.1.55 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 - github.com/mzz2017/softwind v0.0.0-20230710175107-0107af8a1d26 + github.com/mzz2017/softwind v0.0.0-20230722080658-973f985df174 github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd github.com/safchain/ethtool v0.3.0 github.com/sirupsen/logrus v1.9.3 @@ -24,6 +24,7 @@ require ( golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df golang.org/x/sys v0.10.0 google.golang.org/protobuf v1.31.0 + gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) require ( @@ -41,7 +42,6 @@ require ( golang.org/x/net v0.12.0 // indirect golang.org/x/tools v0.11.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect - gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect ) require ( diff --git a/go.sum b/go.sum index 6476a6d2b..6200341b3 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,8 @@ github.com/mzz2017/disk-bloom v1.0.1 h1:rEF9MiXd9qMW3ibRpqcerLXULoTgRlM21yqqJl1B github.com/mzz2017/disk-bloom v1.0.1/go.mod h1:JLHETtUu44Z6iBmsqzkOtFlRvXSlKnxjwiBRDapizDI= github.com/mzz2017/quic-go v0.0.0-20230706143320-cc858d4932b7 h1:9zmZilN02x3byMB2X3x+B4iyKHkucv70WA4hsyZkjo8= github.com/mzz2017/quic-go v0.0.0-20230706143320-cc858d4932b7/go.mod h1:3H6d55CEofIWWr3gQThiB27+hA3WG5tATtPovzEYPAA= -github.com/mzz2017/softwind v0.0.0-20230710175107-0107af8a1d26 h1:kVjALMAhr+rYw77TfrpD8VNIRbZ2/2pN1AYWBcL6eqM= -github.com/mzz2017/softwind v0.0.0-20230710175107-0107af8a1d26/go.mod h1:Fz8fgR7/dbnfR6RLpeOMkUDyebq4xShdmjj+cE5jnJ4= +github.com/mzz2017/softwind v0.0.0-20230722080658-973f985df174 h1:I4JKJSOCxUtFgiMB5VpoqdC70tncD1UkKd2Qvi5/A0o= +github.com/mzz2017/softwind v0.0.0-20230722080658-973f985df174/go.mod h1:Fz8fgR7/dbnfR6RLpeOMkUDyebq4xShdmjj+cE5jnJ4= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=