connect-static-file
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -9,17 +9,25 @@ 'use strict'; | ||
{ | ||
options = options || {}; | ||
options = { | ||
encoded: options.encoded, | ||
headers: {}, // name => value | ||
// `send` options | ||
etag: options.etag, | ||
extensions : options.extensions, | ||
var sendOptions = { | ||
dotfiles : 'allow', | ||
etag : options.etag, | ||
extensions : options.extensions, | ||
index : false, | ||
lastModified: options.lastModified, | ||
maxAge: options.maxAge, | ||
index: false, | ||
dotfiles: 'allow', | ||
root: path | ||
maxAge : options.maxAge, | ||
root : path | ||
}; | ||
var encoded = options.encoded; | ||
var headers = []; | ||
if (options.headers) | ||
{ | ||
Object.keys(options.headers).forEach(function(name) { | ||
headers.push({ | ||
name : name, | ||
value: options.headers[name] | ||
}); | ||
}); | ||
} | ||
return function connectStaticFileMiddleware(request, response, next) | ||
@@ -46,18 +54,14 @@ { | ||
{ | ||
var headers = options.headers || {}; | ||
var keys = Object.keys(headers); | ||
for (var i = 0; i < keys.length; i++) | ||
for (var i = 0; i < headers.length; i++) | ||
{ | ||
var key = keys[i]; | ||
response.setHeader(key, headers[key]); | ||
response.setHeader(headers[i].name, headers[i].value); | ||
} | ||
if (options.encoded) | ||
if (encoded) | ||
{ | ||
response.setHeader('Content-Encoding', options.encoded); | ||
response.setHeader('Content-Encoding', encoded); | ||
} | ||
if (!response.getHeader('Content-Type') && | ||
options.encoded) | ||
encoded) | ||
{ | ||
@@ -75,8 +79,8 @@ // foo.css.gz -> foo.css | ||
if (options.encoded) | ||
if (encoded) | ||
{ | ||
var accept = accepts(request); | ||
var method = accept.encodings([options.encoded]); | ||
if (method !== options.encoded) | ||
var method = accept.encodings([encoded]); | ||
if (method !== encoded) | ||
{ | ||
@@ -88,3 +92,3 @@ next(); | ||
send(request, '', options) | ||
send(request, '', sendOptions) | ||
.on('error', onError) | ||
@@ -95,2 +99,2 @@ .on('directory', onDirectory) | ||
}; | ||
}; | ||
}; |
{ | ||
"name": "connect-static-file", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "connect and express middleware to serve a single static file", | ||
@@ -5,0 +5,0 @@ "main": "lib/connect-static-file.js", |
8671
8
102