move `connect.query()` into our repo
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Roman Shtylman · committed by Roman Shtylman · parent 6b05f60 · Browse files · 4 files·+62 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+62 added−4 removed
- other:+62 added−4 removed
Provenance
- Commit
9bc63d9- Tree
d6ad3de- Author
Roman Shtylman <shtylman@gmail.com>- Committer
Roman Shtylman <shtylman@gmail.com>- Parent
6b05f60
4 files changed+62 added−4 removed
modified:lib/application.js+2 added-3 removed
1 /**2 * Module dependencies.3 */4 5-var connect = require('connect')6- , mixin = require('utils-merge')5+var mixin = require('utils-merge')6 , escapeHtml = require('escape-html')7 , Router = require('./router')8 , methods = require('methods')9 , middleware = require('./middleware')87 unmodified lines97 caseSensitive: this.enabled('case sensitive routing'),98 strict: this.enabled('strict routing')99 });100 102- this._router.use(connect.query());101+ this._router.use(middleware.query());102 this._router.use(middleware.init(this));103 }104 };105 433 unmodified linesmodified:lib/middleware.js+35 added-1 removed
1234566789101118 unmodified lines30313233343536373839404142434445464748495051525354555657585960616263646566
/** * Module dependencies. */
var utils = require('./utils');var parseUrl = require('./utils').parseUrl;var qs = require('qs');
/** * Initialization middleware, exposing the * request and response to eachother, as well18 unmodified lines
next(); }};
/** * Query: * * Automatically parse the query-string when available, * populating the `req.query` object using * [qs](https://github.com/visionmedia/node-querystring). * * Examples: * * .use(connect.query()) * .use(function(req, res){ * res.end(JSON.stringify(req.query)); * }); * * The `options` passed are provided to qs.parse function. * * @param {Object} options * @return {Function} * @api public */
exports.query = function query(options){ return function query(req, res, next){ if (!req.query) { req.query = ~req.url.indexOf('?') ? qs.parse(parseUrl(req).query, options) : {}; }
next(); };};modified:lib/utils.js+24 added
154 unmodified lines155 .replace(/([\/.])/g, '\\$1')156 .replace(/\*/g, '(.*)');157 return new RegExp('^' + path + '$', sensitive ? '' : 'i');158 }159+160+/**161+ * Parse the `req` url with memoization.162+ *163+ * @param {ServerRequest} req164+ * @return {Object}165+ * @api private166+ */167+168+exports.parseUrl = function(req){169+ var parsed = req._parsedUrl;170+ if (parsed && parsed.href == req.url) {171+ return parsed;172+ } else {173+ parsed = parse(req.url);174+175+ if (parsed.auth && !parsed.protocol && ~parsed.href.indexOf('//')) {176+ // This parses pathnames, and a strange pathname like //r@e should work177+ parsed = parse(req.url.replace(/@/g, '%40'));178+ }179+180+ return req._parsedUrl = parsed;181+ }182+};modified:package.json+1 added
33 unmodified lines34353637383940414230 unmodified lines33 unmodified lines "cookie-signature": "1.0.3", "merge-descriptors": "0.0.2", "utils-merge": "1.0.0", "escape-html": "1.0.1", "qs": "0.6.6", "debug": ">= 0.7.3 < 1" }, "devDependencies": { "ejs": "~0.8.4",30 unmodified lines