(req, res, next)
| 10 | * @returns {void} |
| 11 | */ |
| 12 | export function payload (req, res, next) { |
| 13 | if (hasBody(req.method) && req.headers?.[HEADER_CONTENT_TYPE]?.includes(MULTIPART) === false) { |
| 14 | const max = req.server.maxBytes; |
| 15 | let body = EMPTY, |
| 16 | invalid = false; |
| 17 | |
| 18 | req.setEncoding(UTF8); |
| 19 | |
| 20 | req.on(DATA, data => { |
| 21 | if (invalid === false) { |
| 22 | body += data; |
| 23 | |
| 24 | if (max > INT_0 && Buffer.byteLength(body) > max) { |
| 25 | invalid = true; |
| 26 | res.error(INT_413); |
| 27 | } |
| 28 | } |
| 29 | }); |
| 30 | |
| 31 | req.on(END, () => { |
| 32 | if (invalid === false) { |
| 33 | req.body = body; |
| 34 | next(); |
| 35 | } |
| 36 | }); |
| 37 | } else { |
| 38 | next(); |
| 39 | } |
| 40 | } |
no test coverage detected