All files / take-five/lib restrict-post.js

100% Statements 10/10
100% Branches 8/8
100% Functions 2/2
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x 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()
  }
}