Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: pull subscriptions using custom UA #233

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/daeuniverse/dae/config"
"github.com/spf13/cobra"
)

Expand All @@ -17,6 +18,10 @@ var (
}
)

func init() {
config.Version = Version
}

// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
Expand Down
8 changes: 7 additions & 1 deletion common/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"

"github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/config"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down