misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-09-29 12:25:13 +02:00
commit 9469c37ef0
No known key found for this signature in database
GPG key ID: 82E42E7F3B34C97E
2 changed files with 16 additions and 8 deletions

View file

@ -149,15 +149,15 @@ func (s *EventsStream) viewHttpRequest(e session.Event) {
}
if req.Body != nil {
if strings.Contains(req.ContentType, "application/x-www-form-urlencoded") {
if req.IsType("application/x-www-form-urlencoded") {
dump += s.dumpForm(req.Body)
} else if strings.Contains(req.ContentType, "text/plain") {
} else if req.IsType("text/plain") {
dump += s.dumpText(req.Body)
} else if strings.Contains(req.ContentType, "text/xml") {
} else if req.IsType("text/xml") {
dump += s.dumpXML(req.Body)
} else if strings.Contains(req.ContentType, "gzip") {
} else if req.IsType("gzip") {
dump += s.dumpGZIP(req.Body)
} else if strings.Contains(req.ContentType, "application/json") {
} else if req.IsType("application/json") {
dump += s.dumpJSON(req.Body)
} else {
dump += s.dumpRaw(req.Body)
@ -187,11 +187,11 @@ func (s *EventsStream) viewHttpResponse(e session.Event) {
if res.Body != nil {
// TODO: add more interesting response types
if strings.Contains(res.ContentType, "text/plain") {
if res.IsType("text/plain") {
dump += s.dumpText(res.Body)
} else if strings.Contains(res.ContentType, "application/json") {
} else if res.IsType("application/json") {
dump += s.dumpJSON(res.Body)
} else if strings.Contains(res.ContentType, "text/xml") {
} else if res.IsType("text/xml") {
dump += s.dumpXML(res.Body)
}
}

View file

@ -26,6 +26,10 @@ type HTTPRequest struct {
Body []byte `json:"body"`
}
func (r HTTPRequest) IsType(ctype string) bool {
return strings.Contains(r.ContentType, ctype)
}
type HTTPResponse struct {
Protocol string `json:"protocol"`
Status string `json:"status"`
@ -37,6 +41,10 @@ type HTTPResponse struct {
TransferEncoding []string `json:"transfer_encoding"`
}
func (r HTTPResponse) IsType(ctype string) bool {
return strings.Contains(r.ContentType, ctype)
}
func toSerializableRequest(req *http.Request) HTTPRequest {
body := []byte(nil)
ctype := "?"