From 0f5c090ad6185bc1e8b5d5dc07b94e3baeb86eee Mon Sep 17 00:00:00 2001 From: "1808837298@qq.com" <1808837298@qq.com> Date: Tue, 4 Feb 2025 18:10:25 +0800 Subject: [PATCH] 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 --- service/http_client.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/service/http_client.go b/service/http_client.go index 992c73a0..c3f8df7a 100644 --- a/service/http_client.go +++ b/service/http_client.go @@ -42,7 +42,6 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) { return http.DefaultClient, nil } - // 解析代理URL parsedURL, err := url.Parse(proxyURL) if err != nil { return nil, err @@ -57,8 +56,20 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) { }, nil 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 代理拨号器 - dialer, err := proxy.SOCKS5("tcp", parsedURL.Host, nil, proxy.Direct) + dialer, err := proxy.SOCKS5("tcp", parsedURL.Host, auth, proxy.Direct) if err != nil { return nil, err }