* Create a middleware to parse JSON bodies. * * @param {Object} [options] * @returns {Function} * @public
(options)
| 46 | * @public |
| 47 | */ |
| 48 | function json (options) { |
| 49 | const normalizedOptions = normalizeOptions(options, 'application/json') |
| 50 | |
| 51 | const parse = createJsonParser(options) |
| 52 | |
| 53 | const readOptions = { |
| 54 | ...normalizedOptions, |
| 55 | // assert charset per RFC 7159 sec 8.1 |
| 56 | isValidCharset: (charset) => charset.slice(0, 4) === 'utf-' |
| 57 | } |
| 58 | |
| 59 | return function jsonParser (req, res, next) { |
| 60 | read(req, res, next, parse, debug, readOptions) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Create a JSON parse function |
nothing calls this directly
no test coverage detected
searching dependent graphs…