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

View file

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

View file

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