mirror of
https://github.com/projectdiscovery/httpx.git
synced 2024-12-01 12:13:00 +03:00
Merge pull request #389 from projectdiscovery/388-bugfix-content-length
Fixing content-length calculation
This commit is contained in:
commit
9ff0732c99
@ -194,13 +194,18 @@ get_response:
|
||||
respbodystr = h.htmlPolicy.Sanitize(respbodystr)
|
||||
}
|
||||
|
||||
// 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, err := strconv.Atoi(strings.Join(contentLength, ""))
|
||||
if err != nil {
|
||||
resp.ContentLength = utf8.RuneCountInString(respbodystr)
|
||||
} else {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user