Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:mhansen/antinode

  • Loading branch information...
commit a13d3aaa0291eb6d9c57500081655850f5ca0cec 2 parents 03435ac + 70ee2fe
@mhansen authored
Showing with 16 additions and 23 deletions.
  1. +16 −23 lib/antinode.js
View
39 lib/antinode.js
@@ -103,7 +103,7 @@ exports.start = function(custom_settings, callback) {
server.addListener('connection', function(connection) {
connection.setTimeout(settings.timeout_milliseconds);
connection.addListener('timeout', function() {
- log.debug("Connection from",connection.remoteAddress,"timed out.");
+ log.debug("Connection from",connection.remoteAddress,"timed out. Closing it...");
connection.destroy();
});
});
@@ -159,7 +159,7 @@ function serve_static_file(path, req, resp) {
else stream_file(path, stats);
} else if (req.method == 'HEAD') {
send_headers(200, stats.size, mime.mime_type(path), stats.mtime);
- finish(resp);
+ resp.end('');
} else {
return stream_file(path, stats);
}
@@ -176,28 +176,29 @@ function serve_static_file(path, req, resp) {
}
send_headers(200, stats.size, mime.mime_type(file), stats.mtime);
+ sys.pump(readStream, resp, function() {
+ log.debug('pumped',file);
+ });
req.connection.addListener('timeout', function() {
/* dont destroy it when the fd's already closed */
- if (readStream.fd) {
+ if (readStream.readable) {
log.debug('timed out. destroying file read stream');
readStream.destroy();
}
});
- readStream.addListener('open', function() {
- log.debug("opened",path);
- });
- readStream.addListener('data', function (data) {
- // send it out
- resp.write(data);
+ readStream.addListener('fd', function(fd) {
+ log.debug("opened",path,"on fd",fd);
});
+
readStream.addListener('error', function (err) {
log.error('error reading',file,sys.inspect(err));
- finish(resp);
+ resp.end('');
});
- readStream.addListener('end', function () {
- finish(resp);
+ resp.addListener('error', function (err) {
+ log.error('error writing',file,sys.inspect(err));
+ readStream.destroy();
});
}
@@ -205,7 +206,7 @@ function serve_static_file(path, req, resp) {
// no need to send content length or type
log.debug("304 for resource ", path);
send_headers(304);
- finish(resp);
+ resp.end('');
}
function file_not_found() {
@@ -213,20 +214,17 @@ function serve_static_file(path, req, resp) {
var body = "404: " + req.url + " not found.\n";
send_headers(404,body.length,"text/plain");
if (req.method != 'HEAD') {
- resp.write(body);
+ resp.end(body, 'utf-8');
}
- finish(resp);
}
function server_error(message) {
log.error(message);
send_headers(500, message.length, "text/plain");
if (req.method !== 'HEAD') {
- resp.write(message);
+ resp.end(message,'utf-8');
}
- finish(resp);
}
-
}
function execute_sjs(path, req, resp) {
@@ -249,11 +247,6 @@ function execute_sjs(path, req, resp) {
});
}
-function finish(resp) {
- resp.end();
- log.debug("finished response");
-}
-
function close(fd) {
fs.close(fd);
log.debug("closed fd",fd);
Please sign in to comment.
Something went wrong with that request. Please try again.