Skip to content

Commit

Permalink
Change req.query to a getter
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jul 26, 2014
1 parent 91a084b commit 82601d8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 45 deletions.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
- `res.json(obj, status)` signature - use `res.json(status, obj)`
- `res.jsonp(obj, status)` signature - use `res.jsonp(status, obj)`
- `res.send(body, status)` signature - use `res.send(status, body)`
- `express.query` middleware
* change:
- `req.host` now returns host (`hostname:port`) - use `req.hostname` for only hostname
- `req.query` is now a getter instead of a plain property

4.7.0 / 2014-07-25
==================
Expand Down
2 changes: 0 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var mixin = require('utils-merge');
var Router = require('./router');
var methods = require('methods');
var middleware = require('./middleware/init');
var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view');
var http = require('http');
Expand Down Expand Up @@ -100,7 +99,6 @@ app.lazyrouter = function() {
strict: this.enabled('strict routing')
});

this._router.use(query(this.get('query parser fn')));
this._router.use(middleware.init(this));
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ exports.Router = Router;
* Expose middleware
*/

exports.query = require('./middleware/query');
exports.static = require('serve-static');

/**
Expand All @@ -83,6 +82,7 @@ exports.static = require('serve-static');
'limit',
'multipart',
'staticCache',
'query',
].forEach(function (name) {
Object.defineProperty(exports, name, {
get: function () {
Expand Down
30 changes: 0 additions & 30 deletions lib/middleware/query.js

This file was deleted.

23 changes: 23 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ req.range = function(size){
return parseRange(size, range);
};

/**
* Parse the query string of `req.url`.
*
* This uses the "query parser" setting to parse the raw
* string into an object.
*
* @return {String}
* @api public
*/

defineGetter(req, 'query', function query(){
var queryparse = this.app.get('query parser fn');

if (!queryparse) {
// parsing is disabled
return Object.create(null);
}

var querystring = parse(this).query;

return queryparse(querystring);
});

/**
* Return the value of param `name` when present or `defaultValue`.
*
Expand Down
12 changes: 0 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ exports.compileQueryParser = function compileQueryParser(val) {
fn = querystring.parse;
break;
case false:
fn = newObject;
break;
case 'extended':
fn = qs.parse;
Expand Down Expand Up @@ -289,14 +288,3 @@ exports.setCharset = function(type, charset){
// format type
return typer.format(parsed);
};

/**
* Return new empty objet.
*
* @return {Object}
* @api private
*/

function newObject() {
return {};
}

0 comments on commit 82601d8

Please sign in to comment.