Change req.query to a getter
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 8c6f9c4 · Browse files · 6 files·+26 added−45 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+26 added−45 removed
- other:+26 added−45 removed
Provenance
- Commit
dcc4eaa- Tree
5a94ad9- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
8c6f9c4
6 files changed+26 added−45 removed
deleted:lib/middleware/query.js-30 removed
123456789101112131415161718192021222324252627282930/** * Module dependencies. */
var parseUrl = require('parseurl');var qs = require('qs');
/** * @param {Object} options * @return {Function} * @api public */
module.exports = function query(options) { var queryparse = qs.parse;
if (typeof options === 'function') { queryparse = options; options = undefined; }
return function query(req, res, next){ if (!req.query) { var val = parseUrl(req).query; req.query = queryparse(val, options); }
next(); };};modified:lib/application.js-2 removed
5 unmodified lines6 var flatten = require('./utils').flatten;7 var Router = require('./router');8 var methods = require('methods');9 var middleware = require('./middleware/init');10-var query = require('./middleware/query');10 var debug = require('debug')('express:application');11 var View = require('./view');12 var http = require('http');13 var compileETag = require('./utils').compileETag;86 unmodified lines100 caseSensitive: this.enabled('case sensitive routing'),101 strict: this.enabled('strict routing')102 });103 105- this._router.use(query(this.get('query parser fn')));104 this._router.use(middleware.init(this));105 }106 };107 456 unmodified linesmodified:lib/express.js+1 added-1 removed
54 unmodified lines55565758595960616218 unmodified lines8182838485868788894 unmodified lines54 unmodified lines/** * Expose middleware */
exports.query = require('./middleware/query');exports.static = require('serve-static');
/** * Replace removed middleware with an appropriate error message.18 unmodified lines 'directory', 'limit', 'multipart', 'staticCache', 'query',].forEach(function (name) { Object.defineProperty(exports, name, { get: function () { throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');4 unmodified linesmodified:lib/request.js+23 added
182 unmodified lines183 return parseRange(size, range);184 };185 186 /**187+ * Parse the query string of `req.url`.188+ *189+ * This uses the "query parser" setting to parse the raw190+ * string into an object.191+ *192+ * @return {String}193+ * @api public194+ */195+196+defineGetter(req, 'query', function query(){197+ var queryparse = this.app.get('query parser fn');198+199+ if (!queryparse) {200+ // parsing is disabled201+ return Object.create(null);202+ }203+204+ var querystring = parse(this).query;205+206+ return queryparse(querystring);207+});208+209+/**210 * Return the value of param `name` when present or `defaultValue`.211 *212 * - Checks route placeholders, ex: _/user/:id_213 * - Checks body params, ex: id=12, {"id":12}281 unmodified linesmodified:lib/utils.js-12 removed
203 unmodified lines204 case true:205 fn = querystring.parse;206 break;207 case false:208- fn = newObject;208 break;209 case 'extended':210 fn = qs.parse;211 break;56 unmodified lines268 269 // format type270 return typer.format(parsed);271 };273-274-/**275- * Return new empty objet.276- *277- * @return {Object}278- * @api private279- */280-281-function newObject() {282- return {};283-}modified:History.md+2 added
3 unmodified lines4 * remove:5 - `res.json(obj, status)` signature - use `res.json(status, obj)`6 - `res.jsonp(obj, status)` signature - use `res.jsonp(status, obj)`7 - `res.send(body, status)` signature - use `res.send(status, body)`8+ - `express.query` middleware9 * change:10 - `req.host` now returns host (`hostname:port`) - use `req.hostname` for only hostname11+ - `req.query` is now a getter instead of a plain property12 13 4.10.1 / 2014-10-2814 ===================15 2447 unmodified lines