From 9fd638e8078761c7c75410f4f0d793975e6ad60e Mon Sep 17 00:00:00 2001 From: Max Ogden Date: Wed, 19 Dec 2012 13:09:23 -0800 Subject: [PATCH] change http server callback function identity to match the standard node convention --- lib/director/router.js | 6 +++++- test/server/helpers/index.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/director/router.js b/lib/director/router.js index 0640961..51540a2 100644 --- a/lib/director/router.js +++ b/lib/director/router.js @@ -404,6 +404,8 @@ Router.prototype.runlist = function (fns) { // with false, or evaluation will short circuit. // Router.prototype.invoke = function (fns, thisArg, callback) { + var isHttpServerCallback = false + if (thisArg.req && thisArg.res) isHttpServerCallback = true var self = this; if (this.async) { @@ -431,7 +433,9 @@ Router.prototype.invoke = function (fns, thisArg, callback) { return _every(fn, apply); } else if (typeof fn === 'function') { - return fn.apply(thisArg, fns.captures || []); + var args = fns.captures || [] + if (isHttpServerCallback) args = [thisArg.req, thisArg.res].concat(args) + return fn.apply(thisArg, args); } else if (typeof fn === 'string' && self.resource) { self.resource[fn].apply(thisArg, fns.captures || []); diff --git a/test/server/helpers/index.js b/test/server/helpers/index.js index 25630a1..52c92c0 100644 --- a/test/server/helpers/index.js +++ b/test/server/helpers/index.js @@ -20,7 +20,7 @@ exports.createServer = function (router) { }; exports.handlers = { - respondWithId: function (id) { + respondWithId: function (req, res, id) { this.res.writeHead(200, { 'Content-Type': 'text/plain' }) this.res.end('hello from (' + id + ')'); },