From 9124c5d9f5c527660a2b63ade4d981a0e44c339b Mon Sep 17 00:00:00 2001 From: mzz <2017@duck.com> Date: Sun, 23 Jul 2023 23:52:27 +0800 Subject: [PATCH] optimize: pull subscription using custom UA (#233) --- cmd/cmd.go | 5 +++++ common/subscription/subscription.go | 8 +++++++- config/config.go | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 71b64cf..8f7f495 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,6 +1,7 @@ package cmd import ( + "github.com/daeuniverse/dae/config" "github.com/spf13/cobra" ) @@ -17,6 +18,10 @@ var ( } ) +func init() { + config.Version = Version +} + // Execute executes the root command. func Execute() error { return rootCmd.Execute() diff --git a/common/subscription/subscription.go b/common/subscription/subscription.go index d8b665c..86f388e 100644 --- a/common/subscription/subscription.go +++ b/common/subscription/subscription.go @@ -20,6 +20,7 @@ import ( "strings" "github.com/daeuniverse/dae/common" + "github.com/daeuniverse/dae/config" "github.com/sirupsen/logrus" ) @@ -149,6 +150,7 @@ func ResolveSubscription(log *logrus.Logger, client *http.Client, configDir stri log.Debugf("ResolveSubscription: %v", subscription) var ( b []byte + req *http.Request resp *http.Response ) switch u.Scheme { @@ -160,7 +162,11 @@ func ResolveSubscription(log *logrus.Logger, client *http.Client, configDir stri goto resolve default: } - resp, err = client.Get(subscription) + req, err = http.NewRequest("GET", subscription, nil) + if err != nil { + return "", nil, err + } + req.Header.Set("User-Agent", fmt.Sprintf("dae/%v (like v2rayA/1.0 WebRequestHelper) (like v2rayN/1.0 WebRequestHelper)", config.Version)) if err != nil { return "", nil, err } diff --git a/config/config.go b/config/config.go index e8e56de..687a259 100644 --- a/config/config.go +++ b/config/config.go @@ -13,6 +13,10 @@ import ( "github.com/daeuniverse/dae/pkg/config_parser" ) +var ( + Version string +) + type Global struct { TproxyPort uint16 `mapstructure:"tproxy_port" default:"12345"` TproxyPortProtect bool `mapstructure:"tproxy_port_protect" default:"true"`