Skip to content
Myr

req.body takes precedence

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent a592d6c · Browse files · 1 file+9 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−8 removed

  • other:+9 added−8 removed

1 file+9 added−8 removed

modified:lib/request.js+9 added-8 removed
225 unmodified lines
226227/**228 * Return the value of param `name` when present or `defaultValue`.229 *230 * - Checks body params, ex: id=12, {"id":12}231 * - Checks route placeholders, ex: _/user/:id_232 * - Checks query string params, ex: ?id=12232 * - Checks urlencoded body params, ex: id=12233 *234 * To utilize urlencoded request bodies, `req.body`234 * To utilize request bodies, `req.body`235 * should be an object. This can be done by using236 * the `connect.bodyParser` middleware.236 * the `connect.bodyParser()` middleware.237 *238 * @param {String} name239 * @param {Mixed} defaultValue240 * @return {String}241 * @api public242 */243244req.param = function(name, defaultValue){245 // route params like /user/:id245 // req.body246 if (this.body && undefined !== this.body[name]) return this.body[name];247248 // route params249 if (this.params250 && this.params.hasOwnProperty(name)251 && undefined !== this.params[name]) {252 return this.params[name]; 253 }251 // query string params254255 // query-string256 if (undefined !== this.query[name]) return this.query[name]; 257254 // request body params via connect.bodyParser255 if (this.body && undefined !== this.body[name]) return this.body[name];256258 return defaultValue;259};260261/**
120 unmodified lines