-
Notifications
You must be signed in to change notification settings - Fork 34
/
run.go
74 lines (53 loc) · 1.26 KB
/
run.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package hargo
import (
"bufio"
"crypto/tls"
"fmt"
"net/http"
"net/http/cookiejar"
"time"
)
// Run executes all entries in .har file
func Run(r *bufio.Reader, ignoreHarCookies bool, insecureSkipVerify bool) error {
har, err := Decode(r)
if err != nil {
return err
}
check(err)
jar, _ := cookiejar.New(nil)
client := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
Jar: jar,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify},
},
}
if len(har.Log.Entries) == 0 {
return nil
}
first, _ := time.Parse("2006-01-02T15:04:05.000Z", har.Log.Entries[0].StartedDateTime)
for _, entry := range har.Log.Entries {
st, _ := time.Parse("2006-01-02T15:04:05.000Z", entry.StartedDateTime)
diffst := st.Sub(first)
if diffst > 0 {
time.Sleep(diffst * time.Nanosecond)
}
first = st
req, err := EntryToRequest(&entry, ignoreHarCookies)
if err != nil {
return err
}
check(err)
jar.SetCookies(req.URL, req.Cookies())
resp, err := client.Do(req)
check(err)
fmt.Printf("[%s,%v] URL: %s\n", entry.Request.Method, resp.StatusCode, entry.Request.URL)
if resp != nil {
resp.Body.Close()
}
}
return nil
}