Sha256: b012cd8ff072a92103ae3468142ac5c72baf3337658eaca572e355ad35ae2cb4
Contents?: true
Size: 1.37 KB
Versions: 26
Compression:
Stored size: 1.37 KB
Contents
/*! * Ext JS Connect * Copyright(c) 2010 Sencha Inc. * MIT Licensed */ /** * Module dependencies. */ var queryString = require('querystring'); /** * Extract the mime type from the given request's * _Content-Type_ header. * * @param {IncomingMessage} req * @return {String} * @api private */ function mime(req) { var str = req.headers['content-type'] || ''; return str.split(';')[0]; } /** * Supported decoders. * * - application/x-www-form-urlencoded * - application/json */ exports.decode = { 'application/x-www-form-urlencoded': queryString.parse, 'application/json': JSON.parse }; /** * Decode request bodies. * * @return {Function} * @api public */ module.exports = function bodyDecoder(){ return function bodyDecoder(req, res, next) { var decoder = exports.decode[mime(req)]; if (decoder) { var data = ''; req.setEncoding('utf8'); req.addListener('data', function(chunk) { data += chunk; }); req.addListener('end', function() { req.rawBody = data; try { req.body = data ? decoder(data) : {}; } catch (err) { return next(err); } next(); }); } else { next(); } } };
Version data entries
26 entries across 26 versions & 1 rubygems