🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

body-parser

Package Overview
Dependencies
Maintainers
3
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-parser - npm Package Compare versions

Comparing version
2.0.2
to
2.1.0
+11
-1
HISTORY.md

@@ -1,4 +0,14 @@

2.0.2 / 2024-10-30
2.1.0 / 2025-02-10
=========================
* deps:
* type-is@^2.0.0
* debug@^4.4.0
* Removed destroy
* refactor: prefix built-in node module imports
* use the node require cache instead of custom caching
2.0.2 / 2024-10-31
=========================
* remove `unpipe` package and use native `unpipe()` method

@@ -5,0 +15,0 @@

+4
-54

@@ -10,9 +10,2 @@ /*!

/**
* Cache of loaded parsers.
* @private
*/
var parsers = Object.create(null)
/**
* @typedef Parsers

@@ -41,3 +34,3 @@ * @type {function}

enumerable: true,
get: createParserGetter('json')
get: () => require('./lib/types/json')
})

@@ -53,3 +46,3 @@

enumerable: true,
get: createParserGetter('raw')
get: () => require('./lib/types/raw')
})

@@ -65,3 +58,3 @@

enumerable: true,
get: createParserGetter('text')
get: () => require('./lib/types/text')
})

@@ -77,3 +70,3 @@

enumerable: true,
get: createParserGetter('urlencoded')
get: () => require('./lib/types/urlencoded')
})

@@ -93,44 +86,1 @@

}
/**
* Create a getter for loading a parser.
* @private
*/
function createParserGetter (name) {
return function get () {
return loadParser(name)
}
}
/**
* Load a parser module.
* @private
*/
function loadParser (parserName) {
var parser = parsers[parserName]
if (parser !== undefined) {
return parser
}
// this uses a switch for static require analysis
switch (parserName) {
case 'json':
parser = require('./lib/types/json')
break
case 'raw':
parser = require('./lib/types/raw')
break
case 'text':
parser = require('./lib/types/text')
break
case 'urlencoded':
parser = require('./lib/types/urlencoded')
break
}
// store to prevent invoking require()
return (parsers[parserName] = parser)
}

@@ -15,7 +15,6 @@ /*!

var createError = require('http-errors')
var destroy = require('destroy')
var getBody = require('raw-body')
var iconv = require('iconv-lite')
var onFinished = require('on-finished')
var zlib = require('zlib')
var zlib = require('node:zlib')

@@ -94,3 +93,3 @@ /**

req.unpipe()
destroy(stream, true)
stream.destroy()
}

@@ -152,3 +151,2 @@

var length = req.headers['content-length']
var stream

@@ -164,32 +162,36 @@ debug('content-encoding "%s"', encoding)

if (encoding === 'identity') {
req.length = length
return req
}
var stream = createDecompressionStream(encoding, debug)
req.pipe(stream)
return stream
}
/**
* Create a decompression stream for the given encoding.
* @param {string} encoding
* @param {function} debug
* @return {object}
* @api private
*/
function createDecompressionStream (encoding, debug) {
switch (encoding) {
case 'deflate':
stream = zlib.createInflate()
debug('inflate body')
req.pipe(stream)
break
return zlib.createInflate()
case 'gzip':
stream = zlib.createGunzip()
debug('gunzip body')
req.pipe(stream)
break
case 'identity':
stream = req
stream.length = length
break
return zlib.createGunzip()
case 'br':
stream = zlib.createBrotliDecompress()
debug('brotli decompress body')
req.pipe(stream)
break
return zlib.createBrotliDecompress()
default:
throw createError(415, 'unsupported content encoding "' + encoding + '"', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
if (stream === undefined) {
throw createError(415, 'unsupported content encoding "' + encoding + '"', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
return stream
}

@@ -196,0 +198,0 @@

{
"name": "body-parser",
"description": "Node.js body parsing middleware",
"version": "2.0.2",
"version": "2.1.0",
"contributors": [

@@ -12,12 +12,11 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>",

"dependencies": {
"bytes": "3.1.2",
"content-type": "~1.0.5",
"debug": "3.1.0",
"destroy": "1.2.0",
"http-errors": "2.0.0",
"iconv-lite": "0.5.2",
"on-finished": "2.4.1",
"qs": "6.13.0",
"bytes": "^3.1.2",
"content-type": "^1.0.5",
"debug": "^4.4.0",
"http-errors": "^2.0.0",
"iconv-lite": "^0.5.2",
"on-finished": "^2.4.1",
"qs": "^6.14.0",
"raw-body": "^3.0.0",
"type-is": "~1.6.18"
"type-is": "^2.0.0"
},

@@ -34,3 +33,2 @@ "devDependencies": {

"nyc": "15.1.0",
"safe-buffer": "5.2.1",
"supertest": "6.3.3"

@@ -50,3 +48,3 @@ },

"lint": "eslint .",
"test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/",
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-ci": "nyc --reporter=lcov --reporter=text npm test",

@@ -53,0 +51,0 @@ "test-cov": "nyc --reporter=html --reporter=text npm test"