diff --git a/lib/request.js b/lib/request.js index 372a9915e9..3ece922453 100644 --- a/lib/request.js +++ b/lib/request.js @@ -226,7 +226,7 @@ defineGetter(req, 'query', function query(){ var querystring = parse(this).query; return queryparse(querystring); -}); +}, true); /** * Check if the incoming request contains the "Content-Type" @@ -504,12 +504,19 @@ defineGetter(req, 'xhr', function xhr(){ * @param {Object} obj * @param {String} name * @param {Function} getter + * @param {boolean} enableCache * @private */ -function defineGetter(obj, name, getter) { +function defineGetter(obj, name, getter, enableCache) { + let cache; Object.defineProperty(obj, name, { configurable: true, enumerable: true, - get: getter + get: function() { + if (typeof cache === "undefined" || !enableCache) { + cache = getter.call(this); + } + return cache; + } }); }