🐛 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
3 changed files with 27 additions and 5 deletions

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