Comparing version 0.3.0 to 0.3.1
27
index.js
@@ -131,18 +131,29 @@ var common = require('common'); | ||
var url = path.normalize(request.url.split('?')[0]); | ||
var onnotfound = function() { | ||
response.writeHead(404); | ||
response.end(); | ||
}; | ||
if (/\/\.\.\//.test(url)) { // security check | ||
response.writeHead(404); | ||
response.end(); | ||
onnotfound(); | ||
return; | ||
} | ||
fs.stat(url, common.fork(onnotfound, function(stat) { | ||
var ifmod = request.headers['if-modified-since']; | ||
fs.readFile(url, function(err, buffer) { | ||
if (err) { | ||
response.writeHead(404); | ||
if (ifmod && new Date(ifmod) >= stat.mtime) { | ||
response.writeHead(304); | ||
response.end(); | ||
return; | ||
} | ||
response.writeHead(options.status, {'content-type':mimes.resolve(url)}); | ||
response.end(buffer); | ||
}); | ||
response.writeHead(options.status, { | ||
'content-type':mimes.resolve(url), | ||
'content-length':stat.size, | ||
'date':new Date().toUTCString(), | ||
'last-modified':stat.mtime.toUTCString() | ||
}); | ||
fs.createReadStream(url).pipe(response); | ||
})); | ||
}); | ||
@@ -149,0 +160,0 @@ }; |
{ | ||
"name":"router", | ||
"version":"0.3.0", | ||
"version":"0.3.1", | ||
"description":"A lean and mean web router", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
30018
201