Last active
July 15, 2016 13:25
-
-
Save apaleslimghost/a5d06a596f7cf3b44ee6269c573d5642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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