Permalink
Browse files

[fix] do not use middleware code if it's not needed

  • Loading branch information...
1 parent 6ec8d6c commit 20125889b362c61c85924810de446e1e7b18d079 @dominictarr dominictarr committed Aug 2, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/node-http-proxy.js
View
@@ -166,7 +166,7 @@ exports.createServer = function () {
switch (typeof arg) {
case 'string': host = arg; break;
case 'number': port = arg; break;
- case 'function': middleware.push(arg); break;
+ case 'function': middleware.push(handler = callback = arg); break;
case 'object': options = arg; break;
};
});
@@ -203,11 +203,15 @@ exports.createServer = function () {
}
}
- if (middleware.length) {
+ if (middleware.length /*> 1*/) {
//handler = callback = middleware.shift()
//else if (middleware.length)
handler = callback = stack(middleware, proxy);
}
+ else if (middleware.length) { //do not use middleware code if it's not needed.
+ var h = middleware[0]
+ handler = callback = function (req,res) { h(req,res,proxy) };
+ }
if (!handler) {
//

0 comments on commit 2012588

Please sign in to comment.