Skip to content

Commit

Permalink
feat: support users to customize download ua
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Sep 7, 2023
1 parent a1eab12 commit 7286391
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions component/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import (
"time"

"github.com/Dreamacro/clash/component/tls"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/listener/inner"
)

const (
UA = "clash.meta"
)

func HttpRequest(ctx context.Context, url, method string, header map[string][]string, body io.Reader) (*http.Response, error) {
UA := C.UA
method = strings.ToUpper(method)
urlRes, err := URL.Parse(url)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type General struct {
Sniffing bool `json:"sniffing"`
EBpf EBpf `json:"-"`
GlobalClientFingerprint string `json:"global-client-fingerprint"`
GlobalUA string `json:"global-ua"`
KeepAliveInterval int `json:"keep-alive-interval"`
}

Expand Down Expand Up @@ -284,6 +285,7 @@ type RawConfig struct {
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
FindProcessMode P.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"`
GlobalClientFingerprint string `yaml:"global-client-fingerprint"`
GlobalUA string `yaml:"global-ua"`
KeepAliveInterval int `yaml:"keep-alive-interval"`

Sniffer RawSniffer `yaml:"sniffer"`
Expand Down Expand Up @@ -370,6 +372,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
ProxyGroup: []map[string]any{},
TCPConcurrent: false,
FindProcessMode: P.FindProcessStrict,
GlobalUA: "clash.meta",
Tun: RawTun{
Enable: false,
Device: "",
Expand Down Expand Up @@ -571,6 +574,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
C.GeoSiteUrl = cfg.GeoXUrl.GeoSite
C.MmdbUrl = cfg.GeoXUrl.Mmdb
C.GeodataMode = cfg.GeodataMode
C.UA = cfg.GlobalUA
if cfg.KeepAliveInterval != 0 {
N.KeepAliveInterval = time.Duration(cfg.KeepAliveInterval) * time.Second
}
Expand Down Expand Up @@ -617,6 +621,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
FindProcessMode: cfg.FindProcessMode,
EBpf: cfg.EBpf,
GlobalClientFingerprint: cfg.GlobalClientFingerprint,
GlobalUA: cfg.GlobalUA,
KeepAliveInterval: cfg.KeepAliveInterval,
}, nil
}
Expand Down
5 changes: 5 additions & 0 deletions constant/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constant

var (
UA string
)

0 comments on commit 7286391

Please sign in to comment.