Skip to content

Commit

Permalink
Feat: Improve HTTP Headers serializer json log #172 (#173)
Browse files Browse the repository at this point in the history
* Changed Event struct, field headers from string to map[string][]string

* Add integration test for http Headers
  • Loading branch information
mariocandela authored Mar 1, 2025
1 parent f658a26 commit 1f59685
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
3 changes: 3 additions & 0 deletions integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ func (suite *IntegrationTestSuite) TestInvokeHTTPHoneypot() {
response, err := resty.New().R().
Get(suite.httpHoneypotHost + "/index.php")

response.Header().Del("Date")

suite.Require().NoError(err)
suite.Equal(http.StatusOK, response.StatusCode())
suite.Equal(http.Header{"Content-Length": []string{"15"}, "Content-Type": []string{"text/html"}, "Server": []string{"Apache/2.4.53 (Debian)"}, "X-Powered-By": []string{"PHP/7.4.29"}}, response.Header())
suite.Equal("mocked response", string(response.Body()))

response, err = resty.New().R().
Expand Down
14 changes: 1 addition & 13 deletions protocols/strategies/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
HostHTTPRequest: request.Host,
UserAgent: request.UserAgent(),
Cookies: mapCookiesToString(request.Cookies()),
Headers: mapHeaderToString(request.Header),
Headers: request.Header,
Status: tracer.Stateless.String(),
RemoteAddr: request.RemoteAddr,
SourceIp: host,
Expand All @@ -133,18 +133,6 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
tr.TraceEvent(event)
}

func mapHeaderToString(headers http.Header) string {
headersString := ""

for key := range headers {
for _, values := range headers[key] {
headersString += fmt.Sprintf("[Key: %s, values: %s],", key, values)
}
}

return headersString
}

func mapCookiesToString(cookies []*http.Cookie) string {
cookiesString := ""

Expand Down
2 changes: 1 addition & 1 deletion tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Event struct {
User string
Password string
Client string
Headers string
Headers map[string][]string
Cookies string
UserAgent string
HostHTTPRequest string
Expand Down

0 comments on commit 1f59685

Please sign in to comment.