Add SOCKS5 dialer

See: https://github.com/valyala/fasthttp/issues/161
This commit is contained in:
Erik Dubbelboer
2018-09-01 18:57:38 +08:00
committed by Kirill Danshin
parent d7688109a5
commit 7529e6b2e5
+25
View File
@@ -0,0 +1,25 @@
package fasthttpproxy
import (
"net"
"github.com/valyala/fasthttp"
"golang.org/x/net/proxy"
)
// FasthttpSocksDialer returns a fasthttp.DialFunc that dials using
// the provided SOCKS5 proxy.
//
// Example usage:
// c := &fasthttp.Client{
// Dial: fasthttpproxy.FasthttpSocksDialer("localhost:9050"),
// }
func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
return func(addr string) (net.Conn, error) {
dialer, err := proxy.SOCKS5("tcp", proxyAddr, nil, proxy.Direct)
if err != nil {
return nil, err
}
return dialer.Dial("tcp", addr)
}
}