MCPcopy Create free account
hub / github.com/QuantumNous/new-api / newHTTPClient

Function newHTTPClient

controller/model_sync.go:86–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84)
85
86func 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
115var (
116 httpClientOnce sync.Once

Callers 1

getHTTPClientFunction · 0.85

Calls 3

GetEnvOrDefaultFunction · 0.92
CloneMethod · 0.80
DialContextMethod · 0.80

Tested by

no test coverage detected