optimize reading http request body

master
kevin 4 years ago
parent 952de5eacd
commit 40895ba8d9

@ -42,7 +42,14 @@ func decryptBody(key []byte, r *http.Request) error {
return errContentLengthExceeded
}
content, err := ioutil.ReadAll(io.LimitReader(r.Body, maxBytes))
var content []byte
var err error
if r.ContentLength > 0 {
content = make([]byte, r.ContentLength, r.ContentLength)
_, err = io.ReadFull(r.Body, content)
} else {
content, err = ioutil.ReadAll(io.LimitReader(r.Body, maxBytes))
}
if err != nil {
return err
}

Loading…
Cancel
Save