Skip to content

Commit

Permalink
maxapi: create an isolated http transport rather than the default one
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 16, 2021
1 parent 44af6fd commit 59a18b6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/exchange/max/maxapi/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io/ioutil"
"math"
"net"
"net/http"
"net/http/httputil"
"net/url"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 59a18b6

Please sign in to comment.