Merge branch 'master' of git://github.com/aheckmann/express into integration
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents ce4fe24, a435e8e · Browse files · 6 files·+60 added−60 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+60 added−60 removed
- tests:+16 added−16 removed
- other:+44 added−44 removed
Provenance
- Commit
e885421- Tree
8e73ad4- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
ce4fe24- Parent 2
a435e8e
6 files changed+60 added−60 removed
modified:lib/express/plugins/cache.js+4 added-4 removed
24 unmodified lines25 * Override in subclass to provide data-store specific functionality.26 *27 * @param {string} key28 * @param {string} val29- * @param {function} fn29+ * @param {function} callback30 * @api public31 */32 33- set: function(key, val, fn) {33+ set: function(key, val, callback) {34 if (typeof key !== 'string')35 throw new Error(this.name + ' store #set() key must be a string')36 },37 1 unmodified line39 * Ensure that the given _key_ is a string.40 * Override in subclass to provide data-store specific functionality.41 *42 * @param {string} key43- * @param {function} fn43+ * @param {function} callback44 * @api public45 */46 47- get: function(key, fn) {47+ get: function(key, callback) {48 if (typeof key !== 'string')49 throw new Error(this.name + 'store #get() key must be a string')50 },51 177 unmodified linesmodified:lib/express/plugins/hooks.js+12 added-12 removed
6 unmodified lines789101111121313141516171817181920212222232424252627282928293031323320 unmodified lines5455565758595859606162636465666768696869707172736 unmodified lines
exports.callbacks = { before: [], after: [] }
/** * Add a _fn_ to be excuted before a request. * Add a _callback_ to be excuted before a request. * * @param {function} fn * @param {function} callback * @api public */
exports.before = function(fn) { exports.callbacks.before.push(fn)exports.before = function(callback) { exports.callbacks.before.push(callback)}
/** * Add a _fn_ to be excuted after a request. * Add a _callback_ to be excuted after a request. * * @param {function} fn * @param {function} callback * @api public */
exports.after = function(fn) { exports.callbacks.after.push(fn)exports.after = function(callback) { exports.callbacks.after.push(callback)}
// --- Hooks
20 unmodified lines * Invoke all before handlers. */ request: function(event) { exports.callbacks.before.each(function(fn){ fn.call(event.request, event.request) exports.callbacks.before.each(function(callback){ callback.call(event.request, event.request) }) }, /** * Invoke all after handlers. */ response: function(event) { exports.callbacks.after.each(function(fn){ fn.call(event.request, event.request) exports.callbacks.after.each(function(callback){ callback.call(event.request, event.request) }) } }})No newline at end of fileNo newline at end of filemodified:lib/express/spec/mocks.js+16 added-16 removed
10 unmodified lines11 /**12 * Sync fs.readFile()13 */14 15-fs.readFile = function(path, encoding, fn) {15+fs.readFile = function(path, encoding, callback) {16 if (encoding instanceof Function)17- fn = encoding,17+ callback = encoding,18 encoding = null19 try {20- fn(null, fs.readFileSync(path, encoding))20+ callback(null, fs.readFileSync(path, encoding))21 } catch (e) {22- fn(e)22+ callback(e)23 }24 }25 26 /**27 * Sync path.exists()28 */29 30-path.exists = function(path, fn) {30+path.exists = function(path, callback) {31 try {32 fs.statSync(path)33- fn(true)33+ callback(true)34 } catch (e) {35- fn(false)35+ callback(false)36 }37 }38 39 /**40 * Sync fs.stat()41 */42 43-fs.stat = function(path, fn) {43+fs.stat = function(path, callback) {44 try {45- fn(null, fs.statSync(path))45+ callback(null, fs.statSync(path))46 } catch (e) {47- fn(e)47+ callback(e)48 }49 }50 51 // --- MockRequest73 unmodified lines125 * @return {MockResponse}126 * @api private127 */128 129-function request(method, path, options, fn) {129+function request(method, path, options, callback) {130 var response = new MockResponse131 var request = new MockRequest(method, path, options)132 Express.server.route(request, response)133 return response24 unmodified lines158 * @api private159 */160 161 function route(method) {162- return function(path, options, fn){162+ return function(path, options, callback){163 if (options instanceof Function)164- fn = options, options = {}165- if (fn instanceof Function)166- Express.routes.push(new Route(method, path, fn, options))164+ callback = options, options = {}165+ if (callback instanceof Function)166+ Express.routes.push(new Route(method, path, callback, options))167 else168- return request(method, path, options, fn)168+ return request(method, path, options, callback)169 }170 }171 172 // --- Mock routing API5 unmodified linesmodified:lib/express/core.js+5 added-5 removed
20 unmodified lines21 Route = new Class({22 23 /**24 * Initialize a route with the given _method_,25- * _path_, and callback _fn_.25+ * _path_, and callback _callback_.26 *27 * The given _path_ becomes #originalPath, 28 * #path is then a normalized version converted29 * to a regular expression for routing.30 *31 * @param {string} method32 * @param {string} path33- * @param {function} fn33+ * @param {function} callback34 * @param {hash} options35 * @api private36 */37 38- constructor: function(method, path, fn, options){38+ constructor: function(method, path, callback, options){39 this.method = method40 this.originalPath = path41 this.path = this.normalize(path)42- this.fn = fn42+ this.callback = callback43 },44 45 /**46 * Normalize _path_. When a RegExp it is simply returned,60 unmodified lines107 route: function() { 108 var body, 109 route = this.matchingRoute()110 if (route) {111- body = route.fn.apply(this.request, this.request.captures.slice(1));111+ body = route.callback.apply(this.request, this.request.captures.slice(1));112 if (this.request.passed) {113 if (typeof this.request.passed === 'string')114 this.request.url.pathname = this.request.passed115 this.request.passed = false218 unmodified linesmodified:lib/express/dsl.js+14 added-14 removed
8 unmodified lines9 * @api private10 */11 12 function route(method) {13- return function(path, options, fn){13+ return function(path, options, callback){14 if (options instanceof Function)15- fn = options, options = {}16- Express.routes.push(new Route(method, path, fn, options))15+ callback = options, options = {}16+ Express.routes.push(new Route(method, path, callback, options))17 }18 }19 20 /**55 unmodified lines76 Express.server.run.apply(Express.server, arguments)77 }78 79 /**80- * Configure _env_ with _fn_.80+ * Configure _env_ with _callback_.81 *82 * Global configuration, disregards which83 * environment is active:84 *11 unmodified lines96 * 97 * configure('development')98 *99 * @param {string, function} env100- * @param {function} fn100+ * @param {function} callback101 * @api public102 */103 104-exports.configure = function(env, fn) {104+exports.configure = function(env, callback) {105 if (env instanceof Function)106- fn = env, env = 'all'107- if (fn instanceof Function)108- return Express.config.push([env, fn])106+ callback = env, env = 'all'107+ if (callback instanceof Function)108+ return Express.config.push([env, callback])109 if (typeof env !== 'string')110 throw new TypeError('environment required')111 Express.config.each(function(conf){112 if (conf[0] === env ||2 unmodified lines115 })116 }117 118 /**119- * Pre-process param _key_ with _fn_.119+ * Pre-process param _key_ with _callback_.120 *121 * @param {string} key122- * @param {function} fn122+ * @param {function} callback123 * @api public124 */125 126-exports.param = function(key, fn) {126+exports.param = function(key, callback) {127 if (typeof key !== 'string')128 throw new TypeError('param key must be a string')129- if (typeof fn !== 'function')129+ if (typeof callback !== 'function')130 throw new TypeError('param must pass a function to process "' + key + '"')131- Express.params[key] = fn131+ Express.params[key] = callback132 }133 134 /**135 * Register a "Not Found" route.26 unmodified linesmodified:lib/express/http.js+9 added-9 removed
14 unmodified lines1516171819192021222324242526272816 unmodified lines454647484949505152525354545556575859596061626310 unmodified lines74757677787879808181828383848586875 unmodified lines14 unmodified lines * @param {string} method * @param {string} url * @param {hash} data * @param {hash} headers * @param {function} fn * @param {function} callback * @param {number} redirects * @api private */ function request(method, url, data, headers, fn, redirects) {function request(method, url, data, headers, callback, redirects) { var buf = '', redirects = redirects || 3, url = parse(url), path = url.pathname || '/',16 unmodified lines var req = client.request(method, path + search + hash, headers) if (data && method !== 'GET') req.write(data) req.addListener('response', function(res){ if (req.statusCode < 200 || req.statusCode >= 400) fn(new Error('request failed with status ' + res.statusCode + ' "' + http.STATUS_CODES[res.statusCode] + '"')) callback(new Error('request failed with status ' + res.statusCode + ' "' + http.STATUS_CODES[res.statusCode] + '"')) else if (res.statusCode >= 300 && res.statusCode < 400) if (--redirects) request(method, res.headers.location, headers, data, fn, redirects) request(method, res.headers.location, headers, data, callback, redirects) else fn(new Error('maximum number of redirects reached')) callback(new Error('maximum number of redirects reached')) else { res.setBodyEncoding('utf8') res .addListener('data', function(chunk){ buf += chunk }) .addListener('end', function(){ fn(null, buf, res) }) .addListener('end', function(){ callback(null, buf, res) }) } }) req.close()}10 unmodified lines return function() { var headers, data, args = Array.prototype.slice.call(arguments), url = args.shift(), fn = args.pop(), callback = args.pop(), data = args.shift(), headers = args.shift() if (typeof fn !== 'function') if (typeof callback !== 'function') throw new TypeError('http client requires a callback function') return request(method.toUpperCase(), url, data, headers, fn) return request(method.toUpperCase(), url, data, headers, callback) }}
// --- Public API5 unmodified lines