optimize: pull subscription using custom UA (#233)

This commit is contained in:
mzz
2023-07-23 23:52:27 +08:00
committed by GitHub
parent a2f7c37f4d
commit 9124c5d9f5
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"github.com/daeuniverse/dae/config"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -17,6 +18,10 @@ var (
} }
) )
func init() {
config.Version = Version
}
// Execute executes the root command. // Execute executes the root command.
func Execute() error { func Execute() error {
return rootCmd.Execute() return rootCmd.Execute()

View File

@ -20,6 +20,7 @@ import (
"strings" "strings"
"github.com/daeuniverse/dae/common" "github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/config"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -149,6 +150,7 @@ func ResolveSubscription(log *logrus.Logger, client *http.Client, configDir stri
log.Debugf("ResolveSubscription: %v", subscription) log.Debugf("ResolveSubscription: %v", subscription)
var ( var (
b []byte b []byte
req *http.Request
resp *http.Response resp *http.Response
) )
switch u.Scheme { switch u.Scheme {
@ -160,7 +162,11 @@ func ResolveSubscription(log *logrus.Logger, client *http.Client, configDir stri
goto resolve goto resolve
default: 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 { if err != nil {
return "", nil, err return "", nil, err
} }

View File

@ -13,6 +13,10 @@ import (
"github.com/daeuniverse/dae/pkg/config_parser" "github.com/daeuniverse/dae/pkg/config_parser"
) )
var (
Version string
)
type Global struct { type Global struct {
TproxyPort uint16 `mapstructure:"tproxy_port" default:"12345"` TproxyPort uint16 `mapstructure:"tproxy_port" default:"12345"`
TproxyPortProtect bool `mapstructure:"tproxy_port_protect" default:"true"` TproxyPortProtect bool `mapstructure:"tproxy_port_protect" default:"true"`