File: socks5.go

package info (click to toggle)
golang-github-valyala-fasthttp 1%3A1.59.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: makefile: 34
file content (34 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package fasthttpproxy

import (
	"github.com/valyala/fasthttp"
	"golang.org/x/net/http/httpproxy"
)

// FasthttpSocksDialer returns a fasthttp.DialFunc that dials using
// the provided SOCKS5 proxy.
//
// Example usage:
//
//	c := &fasthttp.Client{
//		Dial: fasthttpproxy.FasthttpSocksDialer("socks5://localhost:9050"),
//	}
func FasthttpSocksDialer(proxyAddr string) fasthttp.DialFunc {
	d := Dialer{Config: httpproxy.Config{HTTPProxy: proxyAddr, HTTPSProxy: proxyAddr}}
	dialFunc, _ := d.GetDialFunc(false)
	return dialFunc
}

// FasthttpSocksDialerDualStack returns a fasthttp.DialFunc that dials using
// the provided SOCKS5 proxy with support for both IPv4 and IPv6.
//
// Example usage:
//
//	c := &fasthttp.Client{
//		Dial: fasthttpproxy.FasthttpSocksDialerDualStack("socks5://localhost:9050"),
//	}
func FasthttpSocksDialerDualStack(proxyAddr string) fasthttp.DialFunc {
	d := Dialer{Config: httpproxy.Config{HTTPProxy: proxyAddr, HTTPSProxy: proxyAddr}, DialDualStack: true}
	dialFunc, _ := d.GetDialFunc(false)
	return dialFunc
}