-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathhttp.go
51 lines (44 loc) · 1.17 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package yiigo
import (
"crypto/tls"
"net"
"net/http"
"time"
"github.com/go-resty/resty/v2"
)
const MaxFormMemory = 32 << 20
const (
HeaderAccept = "Accept"
HeaderAuthorization = "Authorization"
HeaderContentType = "Content-Type"
)
const (
ContentText = "text/plain; charset=utf-8"
ContentJSON = "application/json"
ContentForm = "application/x-www-form-urlencoded"
ContentStream = "application/octet-stream"
ContentFormMultipart = "multipart/form-data"
)
// RestyClient default client for http request
var RestyClient = resty.NewWithClient(NewHttpClient())
// NewHttpClient returns a http client
func NewHttpClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 60 * time.Second,
}).DialContext,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
MaxIdleConns: 0,
MaxIdleConnsPerHost: 1000,
MaxConnsPerHost: 1000,
IdleConnTimeout: 60 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: time.Second,
},
}
}