-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest.go
63 lines (52 loc) · 1.34 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package chromy
import (
"github.com/mafredri/cdp/protocol/network"
)
type watcherStopper func(req *Request) bool
type Request struct {
RequestID network.RequestID
Req *network.RequestWillBeSentReply
Resp *network.ResponseReceivedReply
Failed *network.LoadingFailedReply
Finished *network.LoadingFinishedReply
FromCache bool
}
func (r *Request) Done() bool {
return r.IsFailed() || r.IsFinished() && r.Req != nil
}
func (r *Request) IsFailed() bool {
return r.Failed != nil
}
func (r *Request) IsFinished() bool {
return r.Resp != nil && r.Finished != nil
}
func applyRequestWillBeSentReply(reply *network.RequestWillBeSentReply) func(r *Request) bool {
return func(r *Request) bool {
r.Req = reply
return true
}
}
func applyResponseReceivedReply(reply *network.ResponseReceivedReply) func(r *Request) bool {
return func(r *Request) bool {
r.Resp = reply
return true
}
}
func applyLoadingFailedReply(reply *network.LoadingFailedReply) func(r *Request) bool {
return func(r *Request) bool {
r.Failed = reply
return true
}
}
func applyLoadingFinishedReply(reply *network.LoadingFinishedReply) func(r *Request) bool {
return func(r *Request) bool {
r.Finished = reply
return true
}
}
func applyRequestServedFromCache() func(r *Request) bool {
return func(r *Request) bool {
r.FromCache = true
return false
}
}