/
http-client.go
48 lines (40 loc) · 1.01 KB
/
http-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
/*
* Copyright (c) 2022, Andy Pangaribuan <https://github.com/apangaribuan>.
* All Rights Reserved.
*/
package http
import (
"crypto/tls"
"net/http"
"time"
"github.com/andypangaribuan/project9/p9"
"github.com/gojek/heimdall/v7/httpclient"
)
func (slf *srHttpClient) Do(request *http.Request) (*http.Response, error) {
return slf.client.Do(request)
}
func getHttpClient(skipSecurityChecking bool, timeout *time.Duration) (client *httpclient.Client) {
httpTimeout := 5 * time.Minute
if p9.Conf.DefaultHttpRequestTimeout != nil {
httpTimeout = *p9.Conf.DefaultHttpRequestTimeout
}
if timeout != nil {
httpTimeout = *timeout
}
if !skipSecurityChecking {
client = httpclient.NewClient(httpclient.WithHTTPTimeout(httpTimeout))
} else {
client = httpclient.NewClient(
httpclient.WithHTTPClient(&srHttpClient{
client: http.Client{
Timeout: httpTimeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
}))
}
return
}