Skip to content

Commit

Permalink
Update close -> end for node v0.1.90
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Apr 9, 2010
1 parent 4267eca commit 30ccb40
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/node-router.js
Expand Up @@ -37,21 +37,21 @@ function notFound(req, res, message) {
"Content-Length": message.length
});
res.write(message);
res.close();
res.end();
}

// Modifies req and res to call logger with a log line on each res.close
// Modifies req and res to call logger with a log line on each res.end
// Think of it as "middleware"
function logify(req, res, logger) {
var close = res.close;
res.close = function () {
var end = res.end;
res.end = function () {
// Common Log Format (mostly)
logger((req.socket && req.socket.remoteAddress) + " - - [" + (new Date()).toUTCString() + "]"
+ " \"" + req.method + " " + req.url
+ " HTTP/" + req.httpVersionMajor + "." + req.httpVersionMinor + "\" "
+ res.statusCode + " " + res.output[0].length + " \""
+ (req.headers['referrer'] || "") + "\" \"" + req.headers["user-agent"].split(' ')[0] + "\"");
return close.apply(this, arguments);
return end.apply(this, arguments);
}
var writeHead = res.writeHead;
res.writeHead = function (code) {
Expand Down Expand Up @@ -166,7 +166,7 @@ exports.getServer = function getServer(logger) {
// Performs an HTTP 302 redirect
res.redirect = function redirect(location) {
res.writeHead(302, {"Location": location});
res.close();
res.end();
}

// Performs an internal redirect
Expand All @@ -182,7 +182,7 @@ exports.getServer = function getServer(logger) {
["Content-Length", body.length]
]));
res.write(body);
res.close();
res.end();
}

res.simpleText = function (code, body, extra_headers) {
Expand Down Expand Up @@ -257,8 +257,8 @@ exports.getServer = function getServer(logger) {
logger("node-router server instance at http://" + host + ":" + port + "/");
}

function close() {
return server.close();
function end() {
return server.end();
}

// Return a handle to the public facing functions from this closure as the
Expand All @@ -271,7 +271,7 @@ exports.getServer = function getServer(logger) {
resource: resource,
resourceController: resourceController,
listen: listen,
close: close,
end: end,
};
}

Expand Down Expand Up @@ -308,7 +308,7 @@ exports.staticHandler = function (filename) {
loadResponseData(req, res, function () {
res.writeHead(200, headers);
res.write(body, encoding);
res.close();
res.end();
});
};
};
Expand Down Expand Up @@ -341,7 +341,7 @@ exports.staticDirHandler = function(root, prefix) {
loadResponseData(req, res, filename, function(headers, body, encoding) {
res.writeHead(200, headers);
res.write(body, encoding);
res.close();
res.end();
});
};
};
Expand Down

0 comments on commit 30ccb40

Please sign in to comment.