-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocks5.go
More file actions
34 lines (30 loc) · 865 Bytes
/
socks5.go
File metadata and controls
34 lines (30 loc) · 865 Bytes
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 teleBot
import (
"context"
"fmt"
"net"
"net/http"
"os"
"time"
"golang.org/x/net/proxy"
)
var timeout = time.Second * 30
var httpTransport = &http.Transport{}
var defaultClient = http.Client{Transport: httpTransport, Timeout: timeout}
func SendSOCKS5Request(req *http.Request, proxyAddr string, auth *proxy.Auth, client *http.Client) (*http.Response, error) {
// create a socks5 dialer
dialer, err := proxy.SOCKS5("tcp", proxyAddr, auth, proxy.Direct)
if err != nil {
fmt.Fprintln(os.Stderr, "can't connect to proxy:", err)
return nil, err
}
// set our socks5 as the dialer
// httpTransport.Dial = dialer.Dial -- deprecated
httpTransport.DialContext = func(_ context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
}
if client != nil {
return client.Do(req)
}
return defaultClient.Do(req)
}