mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
maxapi: create an isolated http transport rather than the default one
This commit is contained in:
parent
684232041c
commit
7c5b676366
|
@ -10,6 +10,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
@ -118,9 +119,20 @@ func NewRestClientWithHttpClient(baseURL string, httpClient *http.Client) *RestC
|
|||
}
|
||||
|
||||
func NewRestClient(baseURL string) *RestClient {
|
||||
transport := http.DefaultTransport.(*http.Transport)
|
||||
transport.MaxIdleConnsPerHost = httpTransportMaxIdleConnsPerHost
|
||||
transport.MaxIdleConns = httpTransportMaxIdleConns
|
||||
// create an isolated http transport rather than the default one
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
ForceAttemptHTTP2: true,
|
||||
MaxIdleConns: httpTransportMaxIdleConns,
|
||||
MaxIdleConnsPerHost: httpTransportMaxIdleConnsPerHost,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: defaultHTTPTimeout,
|
||||
|
|
Loading…
Reference in New Issue
Block a user