feat: add read/written bytes from/to request/response

Based on `count-response-size-middleware`.
This commit is contained in:
siiky 2024-11-28 13:01:09 +00:00
parent 255ef6baf7
commit d64c4a4df6
2 changed files with 18 additions and 1 deletions

View file

@ -0,0 +1,15 @@
const addRWBytes = () => (req, res, next) => {
const handle = () => {
res.removeListener('finish', handle)
res.removeListener('close', handle)
res.bytesRead = req.connection.bytesRead
res.bytesWritten = req.connection.bytesWritten
}
res.on('finish', handle)
res.on('close', handle)
next()
}
module.exports = addRWBytes