Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactored req.param()
  • Loading branch information
tj committed Jun 6, 2012
1 parent ebcb1ca commit 99b2e0f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/request.js
Expand Up @@ -223,19 +223,12 @@ req.__defineGetter__('acceptedCharsets', function(){
*/

req.param = function(name, defaultValue){
// route params
if (this.params
&& this.params.hasOwnProperty(name)
&& undefined !== this.params[name]) {
return this.params[name];
}

// req.body
if (this.body && undefined !== this.body[name]) return this.body[name];

// query-string
if (undefined !== this.query[name]) return this.query[name];

var params = this.params || {};
var body = this.body || {};
var query = this.query || {};
if (null != params[name]) return params[name];
if (null != body[name]) return body[name];
if (null != query[name]) return query[name];
return defaultValue;
};

Expand Down

0 comments on commit 99b2e0f

Please sign in to comment.