Skip to content

Instantly share code, notes, and snippets.

@jdavisclark
Created February 12, 2014 02:38
Show Gist options
  • Select an option

  • Save jdavisclark/8949030 to your computer and use it in GitHub Desktop.

Select an option

Save jdavisclark/8949030 to your computer and use it in GitHub Desktop.
var util = require('./util');
module.exports = function(jsgiReq) {
return Object.create(jsgiReq, {
isXMLHttpRequest: getter(function() {
return !util.no(this.headers['x-requested-with']);
}),
_paramGroups: {
routeParams: {
value: {},
enumerable: true
},
search: getter(function() {
return util.extractSearch(jsgiReq);
})
},
params: getter(function() {
var tmp = {}, self = this;
Object.keys(this._paramGroups).forEach(function(group) {
tmp = util.merge(tmp, self._paramGroups[group])
});
return tmp;
})
});
};
/**
* Helper function to create property descriptor that is enumerable
* and has a getter.
*
* @param fn {Function} The getter function.
* @api private
*/
function getter(fn) {
return {
get: fn,
enumerable: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment