Skip to content

Commit

Permalink
Merge pull request #179 from ddosify/perf_fix/body_size_check
Browse files Browse the repository at this point in the history
req body store limit
  • Loading branch information
fatihbaltaci authored Apr 18, 2023
2 parents 6877608 + 8926938 commit 2a004b5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions core/scenario/requester/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,21 @@ func (h *HttpRequester) Send(client *http.Client, envs map[string]interface{}) (
}

if httpReq.Body != nil {
if h.constantBodyReader != nil {
// copy req body for debug
sectionReader := io.NewSectionReader(h.constantBodyReader, 0, int64(len(h.packet.Payload)))
copiedReqBody = make([]byte, len(h.packet.Payload))
sectionReader.Read(copiedReqBody)
if int64(len(h.packet.Payload)) > 300000 {
// Don't store req bodies bigger than 300KB
copiedReqBody = []byte("too long body")
} else {
buf := bytes.Buffer{}
io.Copy(&buf, httpReq.Body)
copiedReqBody = buf.Bytes()
httpReq.Body = io.NopCloser(bytes.NewReader(buf.Bytes()))
if h.constantBodyReader != nil {
// copy req body for debug
sectionReader := io.NewSectionReader(h.constantBodyReader, 0, int64(len(h.packet.Payload)))
copiedReqBody = make([]byte, len(h.packet.Payload))
sectionReader.Read(copiedReqBody)
} else {
buf := bytes.Buffer{}
io.Copy(&buf, httpReq.Body)
copiedReqBody = buf.Bytes()
httpReq.Body = io.NopCloser(bytes.NewReader(buf.Bytes()))
}
}
}

Expand Down

0 comments on commit 2a004b5

Please sign in to comment.