Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tests for HTTP HEAD
  • Loading branch information
mhansen committed Jun 20, 2010
1 parent 80bcf27 commit c2ae65a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/antinode.js
Expand Up @@ -122,6 +122,7 @@ function handle_request(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);
} else {
return stream_file(path, stats);
Expand All @@ -139,15 +140,15 @@ function handle_request(path, req, resp) {
return file_not_found();
}

send_headers(200, stats.size, mime.mime_type(file), stats.mtime);

req.connection.addListener('timeout', function() {
log.debug('timed out. destroying file read stream');
readStream.destroy();
});

log.debug("opened",path);
send_headers(200, stats.size, mime.mime_type(file), stats.mtime);
req.connection.addListener('drain', function() {
// it is safe to write
readStream.addListener('open', function() {
log.debug("opened",path);
});
readStream.addListener('data', function (data) {
// send it out
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ "name" : "antinode"
, "description" : "A simple web server for node.js"
, "version" : "2.0.5"
, "version" : "2.0.6"
, "author" : "Mark Hansen <mark@markhansen.co.nz>"
, "contributors" :
[ "Ben Noordhuis <info@bnoordhuis.nl>"
Expand Down
22 changes: 22 additions & 0 deletions tests/test-head.js
@@ -0,0 +1,22 @@
require('./common');

var files = [
{"name": "smalltext", "statusCode":200},
{"name": "dictionary", "statusCode":200},
{"name": "cat.jpg", "statusCode":200},
{"name": "iwill404", "statusCode":404}
];

files.forEach(function (file) {
exports[file.name] = function(test) {
antinode.start(settings, function() {
test_http(test,
{'method':'HEAD','pathname':'/'+file.name},
{'statusCode':file.statusCode,'body':''},
function() {
antinode.stop();
test.done();
});
});
};
});

0 comments on commit c2ae65a

Please sign in to comment.