Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Sep 9, 2024
1 parent d6d5045 commit 952e193
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion component/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ import (
C "github.com/metacubex/mihomo/constant"
)

var (
ua string
)

func UA() string {
return ua
}

func SetUA(UA string) {
ua = UA
}

func HttpRequest(ctx context.Context, url, method string, header map[string][]string, body io.Reader) (*http.Response, error) {
return HttpRequestWithProxy(ctx, url, method, header, body, "")
}
Expand All @@ -35,7 +47,7 @@ func HttpRequestWithProxy(ctx context.Context, url, method string, header map[st
}

if _, ok := header["User-Agent"]; !ok {
req.Header.Set("User-Agent", C.UA)
req.Header.Set("User-Agent", UA())
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/metacubex/mihomo/component/auth"
"github.com/metacubex/mihomo/component/cidr"
"github.com/metacubex/mihomo/component/fakeip"
mihomoHttp "github.com/metacubex/mihomo/component/http"
"github.com/metacubex/mihomo/component/sniffer"
"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
Expand Down Expand Up @@ -480,7 +481,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
}

func parseGeneral(cfg *RawConfig) (*General, error) {
C.UA = cfg.GlobalUA
mihomoHttp.SetUA(cfg.GlobalUA)

externalUI := cfg.ExternalUI

Expand Down
3 changes: 2 additions & 1 deletion hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/metacubex/mihomo/component/auth"
"github.com/metacubex/mihomo/component/ca"
"github.com/metacubex/mihomo/component/dialer"
mihomoHttp "github.com/metacubex/mihomo/component/http"
"github.com/metacubex/mihomo/component/iface"
"github.com/metacubex/mihomo/component/profile"
"github.com/metacubex/mihomo/component/profile/cachefile"
Expand Down Expand Up @@ -140,7 +141,7 @@ func GetGeneral() *config.General {
TouchAfterLazyPassNum: provider.TouchAfterLazyPassNum(),
PreResolveProcessName: tunnel.PreResolveProcessName(),
TCPConcurrent: dialer.GetTcpConcurrent(),
GlobalUA: C.UA,
GlobalUA: mihomoHttp.UA(),
}

return general
Expand Down

0 comments on commit 952e193

Please sign in to comment.