feat: add SOCKS5 proxy authentication support
- Enhance `NewProxyHttpClient` to handle SOCKS5 proxy authentication - Extract username and password from proxy URL for SOCKS5 proxy configuration - Provide optional authentication for SOCKS5 proxy connections
This commit is contained in:
@@ -42,7 +42,6 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
|
|||||||
return http.DefaultClient, nil
|
return http.DefaultClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析代理URL
|
|
||||||
parsedURL, err := url.Parse(proxyURL)
|
parsedURL, err := url.Parse(proxyURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -57,8 +56,20 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case "socks5":
|
case "socks5":
|
||||||
|
// 获取认证信息
|
||||||
|
var auth *proxy.Auth
|
||||||
|
if parsedURL.User != nil {
|
||||||
|
auth = &proxy.Auth{
|
||||||
|
User: parsedURL.User.Username(),
|
||||||
|
Password: "",
|
||||||
|
}
|
||||||
|
if password, ok := parsedURL.User.Password(); ok {
|
||||||
|
auth.Password = password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建 SOCKS5 代理拨号器
|
// 创建 SOCKS5 代理拨号器
|
||||||
dialer, err := proxy.SOCKS5("tcp", parsedURL.Host, nil, proxy.Direct)
|
dialer, err := proxy.SOCKS5("tcp", parsedURL.Host, auth, proxy.Direct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user