Permalink
Browse files

Last-Modified header

  • Loading branch information...
1 parent bad221d commit 213a4af956d94955d0b5c494cf14dc15bd65922d @mhansen committed Feb 14, 2010
Showing with 15 additions and 16 deletions.
  1. +1 −0 README.markdown
  2. +0 −2 TODO
  3. +14 −14 server.js
View
@@ -56,6 +56,7 @@ E.g. an HTTP request for `/styles/site.css` will will look for the file `/var/ww
- HTTP `Content-Type` header detection from file extension
- HTTP `Content-Length` header support
- HTTP `Date` header
+- HTTP `Last-Modified` header
- Reads files in binary mode - so can serve images and other binary files (not just text)
- Requests to any `directory` try to return `directory/index.html`
- Virtual Hosts
View
2 TODO
@@ -1,3 +1 @@
-move logging code into own module
-add last-modified header
create tests
View
@@ -51,32 +51,32 @@ require("http").createServer(function(req,resp) {
function stream(path, resp) {
- function sendHeaders(httpstatus, content_length, content_type) {
- resp.sendHeader(httpstatus,
- {
- "Content-Type" : content_type ||
- "application/octet-stream",
- "Server" : "Antinode/" + VERSION +
- " Node.js/" + process.version +
- " " + process.platform,
- "Date" : (new Date()).toUTCString(),
- "Content-Length" : content_length
- });
+ function sendHeaders(httpstatus, length, content_type, modified_time) {
+ var headers = {
+ "Content-Type" : content_type || "application/octet-stream",
+ "Server" : "Antinode/"+VERSION+" Node.js/"+process.version,
+ "Date" : (new Date()).toUTCString(),
+ "Content-Length" : length
+ };
+ if (modified_time) {
+ headers["Last-Modified"] = modified_time.toUTCString();
+ }
+ resp.sendHeader(200, headers);
}
fs.stat(path).addCallback(function (stat) {
if (stat.isDirectory()) {
stream(pathlib.join(path, "index.html"), resp); //try dir/index.html
} else {
- streamFile(path, stat.size);
+ streamFile(path, stat.size, stat.mtime);
}
}).addErrback(fileNotFound);
- function streamFile(file, filesize) {
+ function streamFile(file, filesize, last_modified) {
fs.open(file,process.O_RDONLY, 0660).addCallback(function(fd) {
var position = 0;
log.debug("opened",path,"on fd",fd);
if(fd) {
- sendHeaders(200, filesize, mime.mime_type(path));
+ sendHeaders(200, filesize, mime.mime_type(path), last_modified);
read();
function read() {
fs.read(fd,settings.max_bytes_per_read,position, "binary")

0 comments on commit 213a4af

Please sign in to comment.