Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/types/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

var debug = require('debug')('body-parser:raw')
var read = require('../read')
var { normalizeOptions } = require('../utils')
var { normalizeOptions, passthrough } = require('../utils')

/**
* Module exports.
Expand All @@ -31,12 +31,8 @@ module.exports = raw
function raw (options) {
var normalizedOptions = normalizeOptions(options, 'application/octet-stream')

function parse (buf) {
return buf
}

return function rawParser (req, res, next) {
read(req, res, next, parse, debug, {
read(req, res, next, passthrough, debug, {
...normalizedOptions,

// Skip charset validation and parse the body as is
Expand Down
8 changes: 2 additions & 6 deletions lib/types/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

var debug = require('debug')('body-parser:text')
var read = require('../read')
var { normalizeOptions } = require('../utils')
var { normalizeOptions, passthrough } = require('../utils')

/**
* Module exports.
Expand All @@ -31,11 +31,7 @@ module.exports = text
function text (options) {
var normalizedOptions = normalizeOptions(options, 'text/plain')

function parse (buf) {
return buf
}

return function textParser (req, res, next) {
read(req, res, next, parse, debug, normalizedOptions)
read(req, res, next, passthrough, debug, normalizedOptions)
}
}
15 changes: 13 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ var typeis = require('type-is')
/**
* Module exports.
*/

module.exports = {
getCharset,
normalizeOptions
normalizeOptions,
passthrough
}

/**
Expand Down Expand Up @@ -83,3 +83,14 @@ function normalizeOptions (options, defaultType) {
shouldParse
}
}

/**
* Passthrough function that returns input unchanged.
* Used by parsers that don't need to transform the data.
*
* @param {*} value
* @return {*}
*/
function passthrough (value) {
return value
}