Skip to content

Commit

Permalink
change default http user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Mar 17, 2024
1 parent 86ca8eb commit 0d2fbc3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion transport/v2rayhttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,22 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
if !strings.HasPrefix(requestURL.Path, "/") {
requestURL.Path = "/" + requestURL.Path
}
headers := options.Headers.Build()
if host := headers.Get("Host"); host != "" {
headers.Del("Host")
requestURL.Host = host
}
if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36")
}
return &Client{
ctx: ctx,
dialer: dialer,
serverAddr: serverAddr,
requestURL: requestURL,
host: options.Host,
method: options.Method,
headers: options.Headers.Build(),
headers: headers,
transport: transport,
http2: tlsConfig != nil,
}, nil
Expand Down
5 changes: 5 additions & 0 deletions transport/v2rayhttpupgrade/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
for key, value := range options.Headers {
headers[key] = value
}

if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36")
}

return &Client{
dialer: dialer,
tlsConfig: tlsConfig,
Expand Down
2 changes: 1 addition & 1 deletion transport/v2raywebsocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
requestURL.Host = host
}
if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Go-http-client/1.1")
headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36")
}
return &Client{
dialer,
Expand Down

0 comments on commit 0d2fbc3

Please sign in to comment.