Started Request
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent c6cc291 · Browse files · 4 files·+76 added−56 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+76 added−56 removed
- other:+76 added−56 removed
Provenance
- Commit
d7c3d2f- Tree
28ead35- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
c6cc291
4 files changed+76 added−56 removed
modified:lib/express/core.js+3 added-34 removed
2 unmodified lines3 4 process.mixin(require('sys'))5 process.mixin(require('express/exceptions'))6 process.mixin(require('express/collection'))7+process.mixin(require('express/event'))8+process.mixin(require('express/request'))9 process.mixin(require('express/helpers'))10 process.mixin(require('express/plugin'))11 process.mixin(require('express/mime'))12 process.mixin(require('express/view'))13 process.mixin(require('express/dsl'))14 13-// --- Helpers14-15-/**16- * Normalize the given _path_.17- * Strips trailing slashes and whitespace.18- *19- * @param {string} path20- * @return {string}21- * @api private22- */23-24-function normalizePath(path) {25- return path.replace(/[\s\/]*$/g, '')26-}27-15 // --- Route16 17 Route = Class({18 191 unmodified lines210 211 /**212 * Route the given _request_ and _response_.213 *227- * - Defaults response headers to {}228- * - Normalizes the request path to prep for matching routes229- * - Parses urlencoded request bodies230- * - Invokes Express.router.route() to do its job231- * - Responds immediately if the route returns a body string232- *214 * @param {object} request215 * @param {object} response216 * @api private217 */218 219 route: function(request, response){239- var body 240- response.headers = {}, request.params = {}241- request.plugins = $(Express.plugins).map(function(plugin){242- return new plugin.klass(plugin.options) 243- })244- this.request = request, this.response = response245- this.request.uri.path = normalizePath(request.uri.path)246- this.request.uri.params = parseNestedParams(request.uri.params)247- this.request.uri.post = 248- header('content-type') == 'application/x-www-form-urlencoded' ?249- parseParams(request.body) :250- {}251- trigger('request')220+ trigger('request', { request: request = new Request(request, response) })221 try {222 if (typeof (body = (new Express.router).route(request)) == 'string')223 halt(200, body)224 }46 unmodified linesadded:lib/express/event.js+29 added
1234567891011121314151617181920212223242526272829
// Express - Event - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.Event = Class({ /** * Initialize with event _name_ and optional _data_. * * @param {string} name * @param {hash} data * @api private */ init: function(name, data) { this.name = name process.mixin(this, data) }, /** * Return event string. * * @return {string} * @api public */ string: function() { return '[Event ' + this.name + ']' }})No newline at end of filemodified:lib/express/plugin.js-22 removed
12345678910111213141516171819202122232425456754 unmodified lines
// Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
// --- Event
var Event = exports.Event = Class({ /** * Initialize with event _name_ and optional _data_. * * @param {string} name * @param {hash} data * @api private */ init: function(name, data) { this.name = name this.request = Express.server.request this.response = Express.server.response process.mixin(this, data) }})
// --- Helpers
/** * Trigger even _name_ with optional _data_. * * @param {string} name54 unmodified linesadded:lib/express/request.js+44 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344
// Express - Request - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
// --- Helpers
/** * Normalize the given _path_. * Strips trailing slashes and whitespace. * * @param {string} path * @return {string} * @api public */
exports.normalizePath = function(path) { return path.replace(/[\s\/]*$/g, '')}
// --- Request
exports.Request = Class({ /** * 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 this.plugins = $(Express.plugins).map(function(plugin){ return new plugin.klass(plugin.options) }) }})No newline at end of file