-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrequest.go
45 lines (36 loc) · 1.04 KB
/
request.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
package main
import (
"bytes"
"crypto/tls"
"net/http"
"time"
)
var (
transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
IdleConnTimeout: time.Second,
DisableKeepAlives: true,
}
Client = &http.Client{
Transport: transport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
)
func send_request(url, method string, headers map[string]string, requestBody []byte) (*http.Response, error) {
Client.Timeout = time.Duration(flagTimeout) * time.Second
req, err := http.NewRequest(method, url, bytes.NewBuffer(requestBody))
//handling headers
for headerKey, headerValue := range headers {
req.Header.Add(headerKey, headerValue)
}
resp, err := Client.Do(req)
return resp, err
//This handling the request without Content-Type header
//If there is no headers in response add in resp object a Header
if len(resp.Header["Content-Type"]) < 1 {
resp.Header["Content-Type"] = append(resp.Header["Content-Type"], "None/Null")
}
return resp, err
}