forked from Albert-Zhan/httpc
/
client.go
52 lines (42 loc) · 1.04 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
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) {
proxy, _ := url.Parse(proxyUrl)
this.transport.Proxy=http.ProxyURL(proxy)
}
func (this *HttpClient) SetSkipVerify(isSkipVerify bool) {
this.transport.TLSClientConfig=&tls.Config{InsecureSkipVerify: isSkipVerify}
}
func (this *HttpClient) SetTransport(t *http.Transport) *HttpClient {
this.client.Transport=t
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
}