MCPcopy
hub / github.com/bettercap/bettercap / NewJSRequest

Function NewJSRequest

modules/http_proxy/http_proxy_js_request.go:35–75  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

33var header_regexp = regexp.MustCompile(`^\s*(.*?)\s*:\s*(.*)\s*$`)
34
35func NewJSRequest(req *http.Request) *JSRequest {
36 headers := ""
37 cType := ""
38
39 for name, values := range req.Header {
40 for _, value := range values {
41 headers += name + ": " + value + "\r\n"
42
43 if strings.ToLower(name) == "content-type" {
44 cType = value
45 }
46 }
47 }
48
49 client_ip := strings.Split(req.RemoteAddr, ":")[0]
50 client_mac := ""
51 client_alias := ""
52 if endpoint := session.I.Lan.GetByIp(client_ip); endpoint != nil {
53 client_mac = endpoint.HwAddress
54 client_alias = endpoint.Alias
55 }
56
57 jreq := &JSRequest{
58 Client: map[string]string{"IP": client_ip, "MAC": client_mac, "Alias": client_alias},
59 Method: req.Method,
60 Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
61 Scheme: req.URL.Scheme,
62 Hostname: req.URL.Hostname(),
63 Port: req.URL.Port(),
64 Path: req.URL.Path,
65 Query: req.URL.RawQuery,
66 ContentType: cType,
67 Headers: headers,
68
69 req: req,
70 bodyRead: false,
71 }
72 jreq.UpdateHash()
73
74 return jreq
75}
76
77func (j *JSRequest) NewHash() string {
78 hash := fmt.Sprintf("%s.%s.%s.%s.%s.%s.%s.%s.%s.%s",

Callers 2

OnRequestMethod · 0.85
OnResponseMethod · 0.85

Calls 2

UpdateHashMethod · 0.95
GetByIpMethod · 0.80

Tested by

no test coverage detected