update
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/*!
|
||||
* body-parser
|
||||
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('body-parser:raw')
|
||||
var isFinished = require('on-finished').isFinished
|
||||
var read = require('../read')
|
||||
var typeis = require('type-is')
|
||||
var { normalizeOptions } = require('../utils')
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = raw
|
||||
|
||||
/**
|
||||
* Create a middleware to parse raw bodies.
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @return {function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function raw (options) {
|
||||
var { inflate, limit, verify, shouldParse } = normalizeOptions(options, 'application/octet-stream')
|
||||
|
||||
function parse (buf) {
|
||||
return buf
|
||||
}
|
||||
|
||||
return function rawParser (req, res, next) {
|
||||
if (isFinished(req)) {
|
||||
debug('body already parsed')
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
if (!('body' in req)) {
|
||||
req.body = undefined
|
||||
}
|
||||
|
||||
// skip requests without bodies
|
||||
if (!typeis.hasBody(req)) {
|
||||
debug('skip empty body')
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
debug('content-type %j', req.headers['content-type'])
|
||||
|
||||
// determine if request should be parsed
|
||||
if (!shouldParse(req)) {
|
||||
debug('skip parsing')
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
// read
|
||||
read(req, res, next, parse, debug, {
|
||||
encoding: null,
|
||||
inflate,
|
||||
limit,
|
||||
verify
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var reflectGetProto = require('./Reflect.getPrototypeOf');
|
||||
var originalGetProto = require('./Object.getPrototypeOf');
|
||||
|
||||
var getDunderProto = require('dunder-proto/get');
|
||||
|
||||
/** @type {import('.')} */
|
||||
module.exports = reflectGetProto
|
||||
? function getProto(O) {
|
||||
// @ts-expect-error TS can't narrow inside a closure, for some reason
|
||||
return reflectGetProto(O);
|
||||
}
|
||||
: originalGetProto
|
||||
? function getProto(O) {
|
||||
if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
|
||||
throw new TypeError('getProto: not an object');
|
||||
}
|
||||
// @ts-expect-error TS can't narrow inside a closure, for some reason
|
||||
return originalGetProto(O);
|
||||
}
|
||||
: getDunderProto
|
||||
? function getProto(O) {
|
||||
// @ts-expect-error TS can't narrow inside a closure, for some reason
|
||||
return getDunderProto(O);
|
||||
}
|
||||
: null;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
declare function hasSymbolShams(): boolean;
|
||||
|
||||
export = hasSymbolShams;
|
||||
Reference in New Issue
Block a user