Skip to content

Commit

Permalink
Finished the write function setup
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jul 14, 2011
1 parent d043c33 commit afdfdb8
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,52 @@ Static.prototype.write = function (path, req, res) {
write(200, headers, reply.content, mime.encoding);
}

self.manager.debug('served static content ' + path);
self.manager.log.debug('served static content ' + path);
}

var self = this;

if (this.manager.enabled('browser client cache') && this.cache[path]) {
return answer(this.cache[path]);
} else if (this.manager.get('browser client handler')) {
return this.manager.get('browser client handler').call(this, req, res);
} else {
function ready (err, content) {
if (err) {
self.manager.log.warn('Unable to serve file. ' + (err.message || err));
return write(500, null, 'Error serving static ' + path);
}

// store the result in the cache
var reply = self.cache[path] = {
content: content
, length: content.length
, mime: details.mime
};

if (details.gzip){
self.gzip(content, function (err, content) {
if (!err) {
reply.gzip = {
content: content
, length: content.length;
}
}

answer(reply);
});
} else {
answer(reply);
}
};

var details = this.paths[path];
if (details.file) {
fs.readFile(details.file, ready);
} else if(details.callback) {
details.callback.call(this, path, ready);
} else {
write(404, null, 'File handle not found');
}
}
};

0 comments on commit afdfdb8

Please sign in to comment.