diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2018-09-01 18:57:38 +0800 |
---|---|---|
committer | Kirill Danshin <kirill@danshin.pro> | 2018-09-05 19:58:53 +0300 |
commit | 7529e6b2e53231cc4c11f71a1d272e3ebead2dfc (patch) | |
tree | b8623d1b8ecf5a729d99675a6a34e543fcc47078 /fasthttpproxy | |
parent | Reset all fields when releasing a clientConn (diff) | |
download | fasthttp-7529e6b2e53231cc4c11f71a1d272e3ebead2dfc.tar.gz fasthttp-7529e6b2e53231cc4c11f71a1d272e3ebead2dfc.tar.bz2 fasthttp-7529e6b2e53231cc4c11f71a1d272e3ebead2dfc.zip |
Add SOCKS5 dialer
See: https://github.com/valyala/fasthttp/issues/161
Diffstat (limited to 'fasthttpproxy')
-rw-r--r-- | fasthttpproxy/socks5.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fasthttpproxy/socks5.go b/fasthttpproxy/socks5.go new file mode 100644 index 0000000..77d965d --- /dev/null +++ b/fasthttpproxy/socks5.go @@ -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) + } +} |