-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransport.go
More file actions
33 lines (30 loc) · 758 Bytes
/
transport.go
File metadata and controls
33 lines (30 loc) · 758 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
package main
import (
"github.com/sdvcrx/cuttlefish/config"
"net"
"net/http"
"net/url"
"time"
)
var DefaultProxyTransport = &http.Transport{
Proxy: SelectProxy,
// Copy from https://golang.org/pkg/net/http/#RoundTripper
// http.DefaultTransport
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
func SelectProxy(r *http.Request) (*url.URL, error) {
proxy := config.GetInstance().ParentProxies.Next()
if proxy != "" {
logger.Info().Msgf("select proxy: %s", proxy)
return url.Parse(proxy)
}
return nil, nil
}