update
This commit is contained in:
+18
-16
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user