source: code/trunk/vendor/github.com/valyala/fasthttp/fasthttpproxy/socks5.go@ 145

Last change on this file since 145 was 145, checked in by Izuru Yakumo, 22 months ago

Updated the Makefile and vendored depedencies

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 945 bytes
Line 
1package fasthttpproxy
2
3import (
4 "net"
5 "net/url"
6
7 "github.com/valyala/fasthttp"
8 "golang.org/x/net/proxy"
9)
10
11// FasthttpSocksDialer returns a fasthttp.DialFunc that dials using
12// the provided SOCKS5 proxy.
13//
14// Example usage:
15// c := &fasthttp.Client{
16// Dial: fasthttpproxy.FasthttpSocksDialer("socks5://localhost:9050"),
17// }
18func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
19 var (
20 u *url.URL
21 err error
22 dialer proxy.Dialer
23 )
24 if u, err = url.Parse(proxyAddr); err == nil {
25 dialer, err = proxy.FromURL(u, proxy.Direct)
26 }
27 // It would be nice if we could return the error here. But we can't
28 // change our API so just keep returning it in the returned Dial function.
29 // Besides the implementation of proxy.SOCKS5() at the time of writing this
30 // will always return nil as error.
31
32 return func(addr string) (net.Conn, error) {
33 if err != nil {
34 return nil, err
35 }
36 return dialer.Dial("tcp", addr)
37 }
38}
Note: See TracBrowser for help on using the repository browser.