-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclient.go
54 lines (44 loc) · 1.09 KB
/
client.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
52
53
54
package httpc
import (
"crypto/tls"
"net/http"
"net/url"
"time"
)
type HttpClient struct {
client *http.Client
transport *http.Transport
}
func NewHttpClient() *HttpClient {
tr := &http.Transport{}
client := &http.Client{
Transport: tr,
Timeout: 30 * time.Second,
}
return &HttpClient{client: client, transport: tr}
}
func (this *HttpClient) SetProxy(proxyUrl string) *HttpClient {
proxy, _ := url.Parse(proxyUrl)
this.transport.Proxy = http.ProxyURL(proxy)
return this
}
func (this *HttpClient) ClearProxy() *HttpClient {
this.transport.Proxy = nil
return this
}
func (this *HttpClient) SetSkipVerify(isSkipVerify bool) *HttpClient {
this.transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: isSkipVerify}
return this
}
func (this *HttpClient) SetTimeout(t time.Duration) *HttpClient {
this.client.Timeout = t
return this
}
func (this *HttpClient) SetCookieJar(j *CookieJar) *HttpClient {
this.client.Jar = j
return this
}
func (this *HttpClient) SetRedirect(f func(req *http.Request, via []*http.Request) error) *HttpClient {
this.client.CheckRedirect = f
return this
}