1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1x 5x 19x 7x 7x 7x 2x 5x 2x 15x | module.exports = function (maxSize) { return function restrictPost (req, res, next) { if (req.method === 'POST' || req.method === 'PUT') { const type = req.headers['content-type'] const size = req.headers['content-length'] if (type !== 'application/json') { return res.err(415, `POST requests must be application/json not ${type}`) } if (size > maxSize) { return res.err(413, `${size} exceeds maximum size for requests`) } } next() } } |