diff --git a/lib/node-static.js b/lib/node-static.js index 222dc7e..15d8144 100644 --- a/lib/node-static.js +++ b/lib/node-static.js @@ -192,7 +192,7 @@ Server.prototype.serve = function (req, res, callback) { /* Check if we should consider sending a gzip version of the file based on the * file content type and client's Accept-Encoding header value. */ -Server.prototype.gzipOk = function(req, contentType) { +Server.prototype.gzipOk = function (req, contentType) { var enable = this.options.gzip; if(enable && (typeof enable === 'boolean' || @@ -206,20 +206,17 @@ Server.prototype.gzipOk = function(req, contentType) { /* Send a gzipped version of the file if the options and the client indicate gzip is enabled and * we find a .gz file mathing the static resource requested. */ -Server.prototype.respondGzip = function(pathname, status, contentType, _headers, files, stat, req, res, finish) { +Server.prototype.respondGzip = function (pathname, status, contentType, _headers, files, stat, req, res, finish) { var that = this; - if(files.length == 1 && this.gzipOk(req, contentType)) { + if (files.length == 1 && this.gzipOk(req, contentType)) { var gzFile = files[0] + ".gz"; - fs.stat(gzFile, function(e, gzStat) { - if(!e && gzStat.isFile()) { - //console.log('Serving', gzFile, 'to gzip-capable client instead of', files[0], 'new size is', gzStat.size, 'uncompressed size', stat.size); + fs.stat(gzFile, function (e, gzStat) { + if (!e && gzStat.isFile()) { var vary = _headers['Vary']; - _headers['Vary'] = (vary && vary != 'Accept-Encoding'?vary+', ':'')+'Accept-Encoding'; + _headers['Vary'] = (vary && vary != 'Accept-Encoding' ? vary + ', ' : '') + 'Accept-Encoding'; _headers['Content-Encoding'] = 'gzip'; stat.size = gzStat.size; files = [gzFile]; - } else { - //console.log('gzip file not found or error finding it', gzFile, String(e), stat.isFile()); } that.respondNoGzip(pathname, status, contentType, _headers, files, stat, req, res, finish); }); @@ -229,7 +226,7 @@ Server.prototype.respondGzip = function(pathname, status, contentType, _headers, } } -Server.prototype.parseByteRange = function(req, stat) { +Server.prototype.parseByteRange = function (req, stat) { var byteRange = { from: 0, to: 0, @@ -328,12 +325,11 @@ Server.prototype.respondNoGzip = function (pathname, status, contentType, _heade 'Content-Range', 'Content-Type', 'Expires', - 'Last-Modified'].forEach(function(entityHeader) { + 'Last-Modified'].forEach(function (entityHeader) { delete headers[entityHeader]; }); finish(304, headers); } else { - res.writeHead(status, headers); this.stream(key, files, length, startByte, res, function (e) {