Skip to content

Commit

Permalink
Fix: vmess http method may empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamacro committed Aug 3, 2023
1 parent 9e78137 commit 47b6eb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions common/util/manipulation.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion transport/vmess/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net"
"net/http"
"net/textproto"

"github.com/Dreamacro/clash/common/util"
)

type httpConn struct {
Expand Down Expand Up @@ -58,7 +60,7 @@ func (hc *httpConn) Write(b []byte) (int, error) {
}

u := fmt.Sprintf("http://%s%s", host, path)
req, _ := http.NewRequest(hc.cfg.Method, 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[rand.Intn(len(list))])
}
Expand Down

0 comments on commit 47b6eb1

Please sign in to comment.