From 9f530525d7fe6812567ee8a1254878f4228af85b Mon Sep 17 00:00:00 2001 From: sduoduo233 <85996970+sduoduo233@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:16:36 +0800 Subject: [PATCH] fix: method in vmess http-opts is not used --- common/util/manipulation.go | 8 ++++++++ transport/vmess/http.go | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 common/util/manipulation.go diff --git a/common/util/manipulation.go b/common/util/manipulation.go new file mode 100644 index 00000000..d2c861eb --- /dev/null +++ b/common/util/manipulation.go @@ -0,0 +1,8 @@ +package util + +import "github.com/samber/lo" + +func EmptyOr[T comparable](v T, def T) T { + ret, _ := lo.Coalesce(v, def) + return ret +} diff --git a/transport/vmess/http.go b/transport/vmess/http.go index c4f27c4c..d9e73f68 100644 --- a/transport/vmess/http.go +++ b/transport/vmess/http.go @@ -8,6 +8,8 @@ import ( "net/http" "net/textproto" + "github.com/Dreamacro/clash/common/util" + "github.com/zhangyunhao116/fastrand" ) @@ -59,7 +61,7 @@ func (hc *httpConn) Write(b []byte) (int, error) { } u := fmt.Sprintf("http://%s%s", host, path) - req, _ := http.NewRequest("GET", u, bytes.NewBuffer(b)) + req, _ := http.NewRequest(util.EmptyOr(hc.cfg.Method, http.MethodGet), u, bytes.NewBuffer(b)) for key, list := range hc.cfg.Headers { req.Header.Set(key, list[fastrand.Intn(len(list))]) }