🐛 fix: Fixed SOCKS5 Proxy Authentication Issue

* fix(telegram代理): 修复telegram设置socks5加用户名密码无法代理的问题

修复socks5使用代理用户名密码的时候无法连接认证的问题。
This commit is contained in:
ZeroDeng 2024-05-26 23:25:03 +08:00 committed by GitHub
parent eb260652b2
commit 0f658c5a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 5 deletions

View File

@ -53,8 +53,15 @@ func socks5ProxyFunc(ctx context.Context, network, addr string) (net.Conn, error
if err != nil {
return nil, fmt.Errorf("error parsing proxy address: %w", err)
}
proxyDialer, err := proxy.SOCKS5("tcp", proxyURL.Host, nil, proxy.Direct)
var auth *proxy.Auth = nil
password, isSetPassword := proxyURL.User.Password()
if isSetPassword {
auth = &proxy.Auth{
User: proxyURL.User.Username(),
Password: password,
}
}
proxyDialer, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, proxy.Direct)
if err != nil {
return nil, fmt.Errorf("error creating socks5 dialer: %w", err)
}

View File

@ -38,7 +38,15 @@ func setWSProxy(dialer *websocket.Dialer, proxyAddr string) error {
case "http", "https":
dialer.Proxy = http.ProxyURL(proxyURL)
case "socks5":
socks5Proxy, err := proxy.SOCKS5("tcp", proxyURL.Host, nil, proxy.Direct)
var auth *proxy.Auth = nil
password, isSetPassword := proxyURL.User.Password()
if isSetPassword {
auth = &proxy.Auth{
User: proxyURL.User.Username(),
Password: password,
}
}
socks5Proxy, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, proxy.Direct)
if err != nil {
return fmt.Errorf("error creating socks5 dialer: %w", err)
}

View File

@ -235,7 +235,6 @@ func getHttpClient() (httpClient *http.Client) {
common.SysLog("failed to parse TG proxy URL: " + err.Error())
return
}
switch proxyURL.Scheme {
case "http", "https":
httpClient = &http.Client{
@ -244,7 +243,15 @@ func getHttpClient() (httpClient *http.Client) {
},
}
case "socks5":
dialer, err := proxy.SOCKS5("tcp", proxyURL.Host, nil, proxy.Direct)
var auth *proxy.Auth = nil
password, isSetPassword := proxyURL.User.Password()
if isSetPassword {
auth = &proxy.Auth{
User: proxyURL.User.Username(),
Password: password,
}
}
dialer, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, proxy.Direct)
if err != nil {
common.SysLog("failed to create TG SOCKS5 dialer: " + err.Error())
return