Sha256: 3218ed3c7a130ab40733da4c91b312beb8f48e58a039469a7b517578b6650c44

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

/*!
 * body-parser
 * Copyright(c) 2014 Douglas Christopher Wilson
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var bytes = require('bytes')
var read = require('../read')
var typeis = require('type-is')
var typer = require('media-typer')

/**
 * Module exports.
 */

module.exports = text

/**
 * Create a middleware to parse text bodies.
 *
 * @param {object} [options]
 * @return {function}
 * @api public
 */

function text(options) {
  options = options || {};

  var defaultCharset = options.defaultCharset || 'utf-8'
  var inflate = options.inflate !== false
  var limit = typeof options.limit !== 'number'
    ? bytes(options.limit || '100kb')
    : options.limit
  var type = options.type || 'text/plain'
  var verify = options.verify || false

  if (verify !== false && typeof verify !== 'function') {
    throw new TypeError('option verify must be function')
  }

  function parse(buf) {
    return buf
  }

  return function textParser(req, res, next) {
    if (req._body) return next()
    req.body = req.body || {}

    if (!typeis(req, type)) return next()

    // get charset
    var charset = typer.parse(req).parameters.charset || defaultCharset

    // read
    read(req, res, next, parse, {
      encoding: charset,
      inflate: inflate,
      limit: limit,
      verify: verify
    })
  }
}

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
gulp_assets-1.0.0.pre.5 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/lib/types/text.js
gulp_assets-1.0.0.pre.4 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/lib/types/text.js
gulp_assets-1.0.0.pre.3 template/node_modules/gulp-livereload/node_modules/tiny-lr/node_modules/body-parser/lib/types/text.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/body-parser/lib/types/text.js