From 7286391883eedab755dca5e4e6cc6bda476c2793 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Thu, 7 Sep 2023 18:44:58 +0800 Subject: [PATCH] feat: support users to customize download ua --- component/http/http.go | 6 ++---- config/config.go | 5 +++++ constant/http.go | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 constant/http.go diff --git a/component/http/http.go b/component/http/http.go index bcede09f..c5172fcb 100644 --- a/component/http/http.go +++ b/component/http/http.go @@ -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 { diff --git a/config/config.go b/config/config.go index 4421adc2..56c616d0 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` } @@ -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"` @@ -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: "", @@ -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 } @@ -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 } diff --git a/constant/http.go b/constant/http.go new file mode 100644 index 00000000..8e321f6b --- /dev/null +++ b/constant/http.go @@ -0,0 +1,5 @@ +package constant + +var ( + UA string +)