h3
h3 copied to clipboard
Improve parsing in readBody
Describe the feature
I would propose the following optimizations in readBody and would like to know what you think about that @pi0
- Instead of first calling response.text(), use the content-length header to determine if a body is existent (Transfer-Encoding: chunked and form data shouldn't be relevant here, as they have their own helpers)
- Then check the content-type header and call parseURLEncodedBody on request.text() if applies
- Otherwise directly return response.json() instead of passing text to JSON.parse as destr was removed anyway
This would avoid memory overhead for large files and could also enable file/request size limits, which are normally based on the content-length header (DOS protection). Although there might be better places for content-length validation.
Additional information
- [X] Would you be willing to help implement this feature?