()
| 90 | } |
| 91 | |
| 92 | func newHTTPClient() *http.Client { |
| 93 | timeoutSec := common.GetEnvOrDefault("SYNC_HTTP_TIMEOUT_SECONDS", 10) |
| 94 | dialer := &net.Dialer{Timeout: time.Duration(timeoutSec) * time.Second} |
| 95 | transport := &http.Transport{ |
| 96 | MaxIdleConns: 100, |
| 97 | IdleConnTimeout: 90 * time.Second, |
| 98 | TLSHandshakeTimeout: time.Duration(timeoutSec) * time.Second, |
| 99 | ExpectContinueTimeout: 1 * time.Second, |
| 100 | ResponseHeaderTimeout: time.Duration(timeoutSec) * time.Second, |
| 101 | } |
| 102 | if common.TLSInsecureSkipVerify { |
| 103 | transport.TLSClientConfig = common.InsecureTLSConfig |
| 104 | } |
| 105 | transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 106 | host, _, err := net.SplitHostPort(addr) |
| 107 | if err != nil { |
| 108 | host = addr |
| 109 | } |
| 110 | if strings.HasSuffix(host, "github.io") { |
| 111 | if conn, err := dialer.DialContext(ctx, "tcp4", addr); err == nil { |
| 112 | return conn, nil |
| 113 | } |
| 114 | return dialer.DialContext(ctx, "tcp6", addr) |
| 115 | } |
| 116 | return dialer.DialContext(ctx, network, addr) |
| 117 | } |
| 118 | return &http.Client{Transport: transport} |
| 119 | } |
| 120 | |
| 121 | var ( |
| 122 | httpClientOnce sync.Once |
no test coverage detected