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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -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()

View File

@ -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
}

View File

@ -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"`