This commit is contained in:
2026-07-26 21:23:30 +00:00
parent 6fa0e1b9a6
commit 7c262aeb8b
60 changed files with 2359 additions and 582 deletions
+18 -16
View File
@@ -4,9 +4,9 @@
* Module dependencies.
*/
var bytes = require('bytes')
var contentType = require('content-type')
var typeis = require('type-is')
const bytes = require('bytes')
const contentType = require('content-type')
const typeis = require('type-is')
/**
* Module exports.
@@ -25,11 +25,9 @@ module.exports = {
* @private
*/
function getCharset (req) {
try {
return (contentType.parse(req).parameters.charset || '').toLowerCase()
} catch {
return undefined
}
const header = req.headers['content-type']
if (!header) return undefined
return contentType.parse(header).parameters.charset?.toLowerCase()
}
/**
@@ -59,20 +57,24 @@ function normalizeOptions (options, defaultType) {
throw new TypeError('defaultType must be provided')
}
var inflate = options?.inflate !== false
var limit = typeof options?.limit !== 'number'
? bytes.parse(options?.limit || '100kb')
: options?.limit
var type = options?.type || defaultType
var verify = options?.verify || false
var defaultCharset = options?.defaultCharset || 'utf-8'
const inflate = options?.inflate !== false
const limit = typeof options?.limit === 'undefined' || options?.limit === null
? 102400 // 100kb default
: bytes.parse(options.limit)
const type = options?.type || defaultType
const verify = options?.verify || false
const defaultCharset = options?.defaultCharset || 'utf-8'
if (limit === null) {
throw new TypeError(`option limit "${String(options.limit)}" is invalid`)
}
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
const shouldParse = typeof type !== 'function'
? typeChecker(type)
: type