From daa332e7b0f5e2e060e6c136785378905f2dd9a5 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Sun, 12 Nov 2023 02:44:55 +0800 Subject: [PATCH] chore: modify ua --- adapter/provider/provider.go | 2 +- component/geodata/init.go | 4 ++-- component/mmdb/mmdb.go | 2 +- config/utils.go | 3 ++- hub/updater/updater.go | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index aa434a11..5c1b0f76 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -122,7 +122,7 @@ func (pp *proxySetProvider) getSubscriptionInfo() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() resp, err := mihomoHttp.HttpRequest(ctx, pp.Vehicle().(*resource.HTTPVehicle).Url(), - http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return } diff --git a/component/geodata/init.go b/component/geodata/init.go index 0b193c94..842efcc5 100644 --- a/component/geodata/init.go +++ b/component/geodata/init.go @@ -44,7 +44,7 @@ func InitGeoSite() error { func downloadGeoSite(path string) (err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, C.GeoSiteUrl, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, C.GeoSiteUrl, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return } @@ -63,7 +63,7 @@ func downloadGeoSite(path string) (err error) { func downloadGeoIP(path string) (err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, C.GeoIpUrl, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, C.GeoIpUrl, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return } diff --git a/component/mmdb/mmdb.go b/component/mmdb/mmdb.go index f83b9922..d411b2b4 100644 --- a/component/mmdb/mmdb.go +++ b/component/mmdb/mmdb.go @@ -79,7 +79,7 @@ func Instance() Reader { func DownloadMMDB(path string) (err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, C.MmdbUrl, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, C.MmdbUrl, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return } diff --git a/config/utils.go b/config/utils.go index 5a4fecbf..66bf3441 100644 --- a/config/utils.go +++ b/config/utils.go @@ -14,12 +14,13 @@ import ( "github.com/metacubex/mihomo/adapter/outboundgroup" "github.com/metacubex/mihomo/common/structure" mihomoHttp "github.com/metacubex/mihomo/component/http" + C "github.com/metacubex/mihomo/constant" ) func downloadForBytes(url string) ([]byte, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, url, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, url, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return nil, err } diff --git a/hub/updater/updater.go b/hub/updater/updater.go index a3bc9a42..1967af42 100644 --- a/hub/updater/updater.go +++ b/hub/updater/updater.go @@ -17,6 +17,7 @@ import ( mihomoHttp "github.com/metacubex/mihomo/component/http" "github.com/metacubex/mihomo/constant" + C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/log" "github.com/klauspost/cpuid/v2" @@ -231,7 +232,7 @@ const MaxPackageFileSize = 32 * 1024 * 1024 func downloadPackageFile() (err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, packageURL, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, packageURL, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return fmt.Errorf("http request failed: %w", err) } @@ -412,7 +413,7 @@ func copyFile(src, dst string) error { func getLatestVersion() (version string, err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() - resp, err := mihomoHttp.HttpRequest(ctx, versionURL, http.MethodGet, http.Header{"User-Agent": {"mihomo"}}, nil) + resp, err := mihomoHttp.HttpRequest(ctx, versionURL, http.MethodGet, http.Header{"User-Agent": {C.UA}}, nil) if err != nil { return "", fmt.Errorf("get Latest Version fail: %w", err) }