UNPKG

think-payload

Version:
21 lines (17 loc) 546 B
const raw = require('raw-body'); const inflate = require('inflation'); const qs = require('querystring'); module.exports = function(ctx, opts = {}) { const req = ctx.req; // defaults const len = req.headers['content-length']; const encoding = req.headers['content-encoding'] || 'identity'; if (len && encoding === 'identity') opts.length = ~~len; opts.encoding = opts.encoding || 'utf8'; opts.limit = opts.limit || '1mb'; return raw(inflate(req), opts) .then(str => ({ post: qs.parse(str), raw: str })); };