/
historyMetaData.go
81 lines (76 loc) · 2.1 KB
/
historyMetaData.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
75
76
77
78
79
80
81
package intercept
import (
"encoding/json"
"net"
"net/http"
"strings"
"time"
"github.com/empijei/cli/lg"
"github.com/empijei/wapty/ui/apis"
)
//DISCLAIMER use original req AFTER editing the new one
//And use it from a thread that has a readlock on the status
func (rr *ReqResp) parseRequest(req *http.Request) {
this := rr.MetaData
this.Host = req.Host
this.Method = req.Method
this.Path = req.URL.Path
//TODO implement this in a way that does not consume the body
//if len(req.Form) == 0 {
// _ = req.ParseForm()
//}
//this.Params = len(req.Form) > 0
//this supposes to alread have a RLock on the status.
this.Edited = status.ReqResps[this.ID].RawEditedReq != nil
tmp := strings.Split(this.Path, ".")
if !strings.Contains(tmp[len(tmp)-1], "/") {
this.Extension = tmp[len(tmp)-1]
}
ipport := strings.Split(this.Host, ":")
ips, err := net.LookupHost(ipport[0])
if err == nil && len(ips) >= 1 {
this.IP = ips[0]
if len(ipport) >= 2 {
this.Port = ipport[1]
} else {
switch req.URL.Scheme {
case "https":
this.Port = "443"
case "http":
this.Port = "80"
default:
lg.Infof("Port not specified: %s\n", this.Host)
}
}
} else {
lg.Error("Unable to resolve Host: %s\n", this.Host)
}
this.Time = time.Now().String()
sendMetaData(this)
}
//DISCLAIMER use original res AFTER editing the new one
//And use it from a thread that has a readlock on the status
func (rr *ReqResp) parseResponse(res *http.Response) {
this := rr.MetaData
if !this.Edited {
//this supposes to alread have a RLock on the status.
this.Edited = status.ReqResps[this.ID].RawEditedRes != nil
}
this.Status = res.Status
//FIXME
this.Length = res.ContentLength
this.ContentType = res.Header.Get("Content-Type")
this.TLS = res.TLS != nil
tmp := res.Cookies()
for _, cookie := range tmp {
this.Cookies += cookie.String() + "; "
}
sendMetaData(this)
}
func sendMetaData(metaData *apis.ReqRespMetaData) {
metaJSON, err := json.Marshal(metaData)
if err != nil {
lg.Error(err)
}
uiHistory.Send(&apis.Command{Action: apis.HST_METADATA, Args: map[apis.ArgName]string{apis.HST_METADATA: string(metaJSON)}})
}