MCPcopy
hub / github.com/QuantumNous/new-api / newHTTPClient

Function newHTTPClient

controller/model_sync.go:92–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90}
91
92func 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
121var (
122 httpClientOnce sync.Once

Callers 1

getHTTPClientFunction · 0.85

Calls 1

GetEnvOrDefaultFunction · 0.92

Tested by

no test coverage detected