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 + ')'); },