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