Started moving helpers to Request methods
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent d7c3d2f · Browse files · 4 files·+51 added−39 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+51 added−39 removed
- other:+51 added−39 removed
Provenance
- Commit
76cf65f- Tree
7628701- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
d7c3d2f
4 files changed+51 added−39 removed
modified:lib/express/core.js+2 added-1 removed
215 unmodified lines216 * @api private217 */218 219 route: function(request, response){220- trigger('request', { request: request = new Request(request, response) })220+ request = new Request(request, response)221+ request.trigger('request')222 try {223 if (typeof (body = (new Express.router).route(request)) == 'string')224 halt(200, body)225 }46 unmodified linesmodified:lib/express/helpers.js-16 removed
115 unmodified lines116 return header('accept').indexOf(mime(path)) != -1117 }118 119 /**120- * Set response header _key_ and _val_ or get121- * request header value by _key_.122- *123- * @param {string} key124- * @param {string} val125- * @return {string}126- * @api public127- */128-129-exports.header = function(key, val) {130- return val === undefined ?131- Express.server.request.headers[key.toLowerCase()] :132- Express.server.response.headers[key.toLowerCase()] = val133-}134-135-/**120 * Set response status to _code_.121 *122 * @param {int} code123 * @return {int}146 unmodified linesmodified:lib/express/plugin.js-14 removed
123456789101112131415161718567839 unmodified lines
// Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/** * Trigger even _name_ with optional _data_. * * @param {string} name * @param {hash} data * @api public */
exports.trigger = function(name, data) { $(Express.server.request.plugins).each(function(plugin){ plugin.trigger(new Event(name, data)) })}
/** * Push _plugin_ with _options_ to the plugin stack. * * @param {Plugin} plugin * @param {hash} options39 unmodified linesmodified:lib/express/request.js+49 added-8 removed
19 unmodified lines202122232425262728293031323334353637323334353637383938394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848519 unmodified lines
exports.Request = Class({ /** * Route parameters. */ params: {}, /** * Initialize with node's _request_ and _response_ objects. * * @param {object} request * @param {object} response * @api private */ init: function(request, response) { response.headers = {}, request.params = {} request.uri.path = exports.normalizePath(request.uri.path) request.uri.params = parseNestedParams(request.uri.params) request.uri.post = header('content-type') == 'application/x-www-form-urlencoded' ? parseParams(request.body) : {} this.request = request, this.response = response process.mixin(true, this, request) response.headers = {} this.response = response this.uri.path = exports.normalizePath(this.uri.path) this.uri.params = parseNestedParams(this.uri.params) this.plugins = $(Express.plugins).map(function(plugin){ return new plugin.klass(plugin.options) }) this.uri.post = this.header('content-type') == 'application/x-www-form-urlencoded' ? parseParams(this.body) : {} }, /** * Set response header _key_ and _val_ or get * request header value by _key_. * * @param {string} key * @param {string} val * @return {string} * @api public */
header: function(key, val) { return val === undefined ? this.headers[key.toLowerCase()] : this.response.headers[key.toLowerCase()] = val }, /** * Trigger even _name_ with optional _data_. * * @param {string} name * @param {hash} data * @api public */
trigger: function(name, data) { data = process.mixin(data || {}, { request: this, response: this.response }) this.plugins.each(function(plugin){ plugin.trigger(new Event(name, data)) }) }})No newline at end of fileNo newline at end of file