-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgohead.go
45 lines (36 loc) · 982 Bytes
/
gohead.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 gohead
import (
"crypto/tls"
"io/ioutil"
"net/http"
"time"
)
type GoHead struct{}
func NewGoHead() (*GoHead, error) {
goHead := new(GoHead)
return goHead, nil
}
func Probe(target string) (string, map[string][]string, string) {
client := &http.Client{
Timeout: 8 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // lgtm [go/disabled-certificate-check]
Proxy: http.ProxyFromEnvironment,
},
}
req, err := http.NewRequest("GET", target, nil)
if err != nil {
return "", nil, target
}
req.Header.Add("Accept", "*/*")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0")
resp, err := client.Do(req)
if err != nil {
return "", nil, target
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", resp.Header, target
}
return string(body), resp.Header, target
}