Every line of 'express urlencoded' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
36 return function urlencoded(req, res, next) { 37 if (req._body) return next(); 38 req.body = req.body || {}; 39 40 // check Content-Type 41 if ('application/x-www-form-urlencoded' != utils.mime(req)) return next(); 42 43 // flag as parsed 44 req._body = true; 45 46 // parse 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 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
5 export function bodyUrlEncoded() { 6 return urlencoded({ extended: true }); 7 }