1
0
mirror of https://github.com/bettercap/bettercap.git synced 2025-03-12 04:36:03 -07:00

fix: setting other fields in marshaled js http request

This commit is contained in:
evilsocket 2018-01-10 16:54:34 +01:00
parent e8c6c7cf92
commit 9f8aa21136
2 changed files with 26 additions and 13 deletions

@ -7,6 +7,7 @@ const (
RED = "\033[31m"
GREEN = "\033[32m"
BLUE = "\033[34m"
YELLOW = "\033[33m"
FG_BLACK = "\033[30m"

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
type JSHeader struct {
@ -12,30 +13,41 @@ type JSHeader struct {
}
type JSRequest struct {
Method string
Version string
Path string
Hostname string
Headers []JSHeader
Body string
req *http.Request
Client string
Method string
Version string
Path string
Hostname string
ContentType string
Headers []JSHeader
Body string
req *http.Request
}
func NewJSRequest(req *http.Request) JSRequest {
headers := make([]JSHeader, 0)
cType := ""
for key, values := range req.Header {
for _, value := range values {
headers = append(headers, JSHeader{key, value})
if key == "Content-Type" {
cType = value
}
}
}
return JSRequest{
Method: req.Method,
Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
Path: req.URL.Path,
Hostname: req.Host,
Headers: headers,
req: req,
Client: strings.Split(req.RemoteAddr, ":")[0],
Method: req.Method,
Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
Path: req.URL.Path,
Hostname: req.Host,
ContentType: cType,
Headers: headers,
req: req,
}
}