Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active July 15, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apaleslimghost/a5d06a596f7cf3b44ee6269c573d5642 to your computer and use it in GitHub Desktop.
Save apaleslimghost/a5d06a596f7cf3b44ee6269c573d5642 to your computer and use it in GitHub Desktop.
const rawBody = require('raw-body');
const typer = require('media-typer');
const qs = require('querystring');
module.exports = (req, limit = '1mb') => Promise.resolve().then(() => {
const type = req.headers['content-type'];
const length = req.headers['content-length'];
const encoding = typer.parse(type).parameters.charset;
return rawBody(req, { limit, length, encoding }).then(body => {
return qs.parse(body.toString('utf8'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment