Merge pull request #389 from projectdiscovery/388-bugfix-content-length

Fixing content-length calculation
This commit is contained in:
Sandeep Singh 2021-09-06 15:58:02 +05:30 committed by GitHub
commit 9ff0732c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -194,13 +194,18 @@ get_response:
respbodystr = h.htmlPolicy.Sanitize(respbodystr)
}
if contentLength, ok := resp.Headers["Content-Length"]; ok {
contentLengthInt, err := strconv.Atoi(strings.Join(contentLength, ""))
if err != nil {
resp.ContentLength = utf8.RuneCountInString(respbodystr)
} else {
// if content length is not defined
if resp.ContentLength <= 0 {
// check if it's in the header and convert to int
if contentLength, ok := resp.Headers["Content-Length"]; ok {
contentLengthInt, _ := strconv.Atoi(strings.Join(contentLength, ""))
resp.ContentLength = contentLengthInt
}
// if we have a body, then use the number of bytes in the body if the length is still zero
if resp.ContentLength <= 0 && len(respbodystr) > 0 {
resp.ContentLength = utf8.RuneCountInString(respbodystr)
}
}
resp.Data = respbody