diff --git a/instance.go b/instance.go index c8f05f0..73e0a5e 100644 --- a/instance.go +++ b/instance.go @@ -4,11 +4,13 @@ import ( "git.nspix.com/golang/kos/entry/cli" "git.nspix.com/golang/kos/entry/http" _ "git.nspix.com/golang/kos/pkg/request" + _ "git.nspix.com/golang/kos/util/arrays" _ "git.nspix.com/golang/kos/util/bs" _ "git.nspix.com/golang/kos/util/fetch" _ "git.nspix.com/golang/kos/util/humanize" _ "git.nspix.com/golang/kos/util/random" _ "git.nspix.com/golang/kos/util/reflection" + _ "git.nspix.com/golang/kos/util/sys" "sync" ) diff --git a/pkg/request/client.go b/pkg/request/client.go index 2fe6634..e99c18f 100644 --- a/pkg/request/client.go +++ b/pkg/request/client.go @@ -1,10 +1,13 @@ package request import ( + "crypto/tls" "io" + "net" "net/http" "net/http/cookiejar" "strings" + "time" ) type ( @@ -21,6 +24,44 @@ type ( } ) +var ( + DefaultClient = &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + ForceAttemptHTTP2: true, + MaxIdleConns: 64, + MaxIdleConnsPerHost: 8, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + Timeout: time.Second * 30, + } + + UnsafeClient = &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + ForceAttemptHTTP2: true, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + MaxIdleConns: 64, + MaxIdleConnsPerHost: 8, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + Timeout: time.Second * 30, + } +) + func (client *Client) stashUri(urlPath string) string { var ( pos int @@ -139,7 +180,7 @@ func (client *Client) execute(r *Request) (res *http.Response, err error) { func New() *Client { client := &Client{ - client: http.DefaultClient, + client: DefaultClient, interceptorRequest: make([]BeforeRequest, 0, 10), interceptorResponse: make([]AfterRequest, 0, 10), }