36 | return function urlencoded(req, res, next) { |
37 | if (req._body) return next(); |
38 | req.body = req.body || {}; |
39 | |
40 | |
41 | if ('application/x-www-form-urlencoded' != utils.mime(req)) return next(); |
42 | |
43 | |
44 | req._body = true; |
45 | |
46 | |
47 | limit(req, res, function(err){ |
48 | if (err) return next(err); |
49 | var buf = ''; |
50 | req.setEncoding('utf8'); |
51 | req.on('data', function(chunk){ buf += chunk }); |
52 | req.on('end', function(){ |
53 | try { |
54 | req.body = buf.length |
55 | ? qs.parse(buf, options) |
56 | : {}; |
57 | next(); |
58 | } catch (err){ |
59 | err.body = buf; |
60 | next(err); |
61 | } |
62 | }); |
63 | }); |
64 | } |