Skip to content

Commit

Permalink
Added more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jul 14, 2011
1 parent afdfdb8 commit 9e97e6c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Static.prototype.add = function (path, options, callback) {

Static.prototype.write = function (path, req, res) {
/**
* Writes a response, safely
* Write a response without throwing errors because can throw error if the
* response is no longer writable etc.
*
* @api private
*/
Expand All @@ -131,6 +132,13 @@ Static.prototype.write = function (path, req, res) {
} catch (e) {}
}

/**
* Answers requests depending on the request properties and the reply object.
*
* @param {Object} reply The details and content to reply the response with
* @api private
*/

function answer (reply) {
var cached = req.headers['if-none-match'] === self.etag;
if (cached && self.manager.enabled('browser client cache') {
Expand Down Expand Up @@ -164,11 +172,20 @@ Static.prototype.write = function (path, req, res) {

var self = this;

// most common case first
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 {
/**
* A small helper function that will let us deal with fs and dynamic files
*
* @param {Object} err Optional error
* @param {Buffer} content The data
* @api private
*/

function ready (err, content) {
if (err) {
self.manager.log.warn('Unable to serve file. ' + (err.message || err));
Expand All @@ -182,6 +199,7 @@ Static.prototype.write = function (path, req, res) {
, mime: details.mime
};

// check if we need to gzip it
if (details.gzip){
self.gzip(content, function (err, content) {
if (!err) {
Expand Down

0 comments on commit 9e97e6c

Please sign in to comment.