Skip to content

Commit

Permalink
调整:如果Proxy不是socks5协议,则自动添加socks5协议
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Aug 23, 2024
1 parent 9ec8bbb commit d9bb4eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 16 additions & 0 deletions http/convertSocks5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package http

import "strings"

// ConvertSocks5 如果With.Proxy不是socks5协议,则自动添加socks5协议
func ConvertSocks5(proxy string) string {
index := strings.Index(proxy, "://")
if index == -1 {
return "socks5://" + proxy
}

if !strings.HasPrefix(strings.ToLower(proxy), "socks5://") {
return "socks5" + proxy[index:]
}
return proxy
}
1 change: 1 addition & 0 deletions http/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Download(url string, savePath string, head map[string]any, requestTimeout i

// 设置代理
if proxyAddr != "" {
proxyAddr = ConvertSocks5(proxyAddr)
fastHttpClient.Dial = fasthttpproxy.FasthttpSocksDialer(proxyAddr)
}

Expand Down
4 changes: 1 addition & 3 deletions http/httpRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ func tryRequestProxy(methodName string, requestUrl string, head map[string]any,
}
// 设置代理
if proxyAddr != "" {
if index := strings.Index(proxyAddr, "://"); index > -1 && !strings.HasPrefix(strings.ToLower(proxyAddr), "socks5://") {
proxyAddr = "socks5" + proxyAddr[index:]
}
proxyAddr = ConvertSocks5(proxyAddr)
fastHttpClient.Dial = fasthttpproxy.FasthttpSocksDialer(proxyAddr)
}
var err error
Expand Down

0 comments on commit d9bb4eb

Please sign in to comment.