-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (59 loc) · 1.37 KB
/
main.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
package main
import (
"bufio"
"github.com/gourmetproject/gourmet"
"net/http"
)
type Request struct {
Method string
URL string
Headers http.Header
ContentLength int64
TransferEncoding []string
Host string
}
type Response struct {
Status string
Headers http.Header
ContentLength int64
}
type Http map[string]interface{}
func (h *Http) Key() string {
return "http"
}
type httpAnalyzer struct{}
func NewAnalyzer() gourmet.Analyzer {
return &httpAnalyzer{}
}
func (ha *httpAnalyzer) Filter(c *gourmet.Connection) bool {
if c.SourcePort == 80 || c.DestinationPort == 80 {
return true
}
return false
}
func (ha *httpAnalyzer) Analyze(c *gourmet.Connection) (gourmet.Result, error) {
h := Http{}
r := bufio.NewReader(c.Payload)
req, err := http.ReadRequest(r)
if err != nil {
return nil, err
}
h["Request"] = Request{
Method: req.Method,
URL: req.URL.String(),
Headers: req.Header,
ContentLength: req.ContentLength,
TransferEncoding: req.TransferEncoding,
Host: req.Host,
}
resp, err := http.ReadResponse(r, req)
if err != nil {
return nil, err
}
h["Response"] = Response{
Status: resp.Status,
Headers: resp.Header,
ContentLength: resp.ContentLength,
}
return &h, nil
}