forked from bepass-org/bepass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
34 lines (31 loc) · 956 Bytes
/
http.go
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 dialer provides utilities for creating custom HTTP clients with
// flexible dialing options.
package dialer
import (
"context"
"crypto/tls"
"net"
"net/http"
"net/url"
)
// MakeHTTPClient creates an HTTP client with custom dialing behavior.
func (d *Dialer) MakeHTTPClient(enableProxy bool) *http.Client {
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
ForceAttemptHTTP2: false,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.TCPDial(network, addr)
},
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return d.TLSDial(func(network, addr string) (net.Conn, error) {
return d.TCPDial(network, addr)
}, network, addr)
},
}
if enableProxy {
proxyURL, _ := url.Parse(d.ProxyAddress)
// Create dialer
transport.Proxy = http.ProxyURL(proxyURL)
}
return &http.Client{Transport: transport}
}