|
@@ -1,10 +1,13 @@
|
|
package request
|
|
package request
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "crypto/tls"
|
|
"io"
|
|
"io"
|
|
|
|
+ "net"
|
|
"net/http"
|
|
"net/http"
|
|
"net/http/cookiejar"
|
|
"net/http/cookiejar"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
type (
|
|
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 {
|
|
func (client *Client) stashUri(urlPath string) string {
|
|
var (
|
|
var (
|
|
pos int
|
|
pos int
|
|
@@ -139,7 +180,7 @@ func (client *Client) execute(r *Request) (res *http.Response, err error) {
|
|
|
|
|
|
func New() *Client {
|
|
func New() *Client {
|
|
client := &Client{
|
|
client := &Client{
|
|
- client: http.DefaultClient,
|
|
|
|
|
|
+ client: DefaultClient,
|
|
interceptorRequest: make([]BeforeRequest, 0, 10),
|
|
interceptorRequest: make([]BeforeRequest, 0, 10),
|
|
interceptorResponse: make([]AfterRequest, 0, 10),
|
|
interceptorResponse: make([]AfterRequest, 0, 10),
|
|
}
|
|
}
|