send
Advanced tools
Comparing version 0.15.6 to 0.16.0
@@ -0,1 +1,12 @@ | ||
0.16.0 / 2017-09-27 | ||
=================== | ||
* Add `immutable` option | ||
* Fix missing `</html>` in default error & redirects | ||
* Use instance methods on steam to check for listeners | ||
* deps: mime@1.4.1 | ||
- Add 70 new types for file extensions | ||
- Set charset as "UTF-8" for .js and .json | ||
* perf: improve path validation speed | ||
0.15.6 / 2017-09-22 | ||
@@ -2,0 +13,0 @@ =================== |
59
index.js
@@ -22,3 +22,2 @@ /*! | ||
var etag = require('etag') | ||
var EventEmitter = require('events').EventEmitter | ||
var fresh = require('fresh') | ||
@@ -76,10 +75,2 @@ var fs = require('fs') | ||
/** | ||
* Shim EventEmitter.listenerCount for node.js < 0.10 | ||
*/ | ||
/* istanbul ignore next */ | ||
var listenerCount = EventEmitter.listenerCount || | ||
function (emitter, type) { return emitter.listeners(type).length } | ||
/** | ||
* Return a `SendStream` for `req` and `path`. | ||
@@ -151,2 +142,6 @@ * | ||
this._immutable = opts.immutable !== undefined | ||
? Boolean(opts.immutable) | ||
: false | ||
this._index = opts.index !== undefined | ||
@@ -277,3 +272,3 @@ ? normalizeList(opts.index, 'index option') | ||
// emit if listeners instead of responding | ||
if (listenerCount(this, 'error') !== 0) { | ||
if (hasListeners(this, 'error')) { | ||
return this.emit('error', createError(status, err, { | ||
@@ -487,3 +482,3 @@ expose: false | ||
if (listenerCount(this, 'directory') !== 0) { | ||
if (hasListeners(this, 'directory')) { | ||
this.emit('directory', res, path) | ||
@@ -542,4 +537,7 @@ return | ||
if (root !== null) { | ||
// normalize | ||
path = normalize('.' + sep + path) | ||
// malicious path | ||
if (UP_PATH_REGEXP.test(normalize('.' + sep + path))) { | ||
if (UP_PATH_REGEXP.test(path)) { | ||
debug('malicious path "%s"', path) | ||
@@ -550,8 +548,8 @@ this.error(403) | ||
// explode path parts | ||
parts = path.split(sep) | ||
// join / normalize from optional root dir | ||
path = normalize(join(root, path)) | ||
root = normalize(root + sep) | ||
// explode path parts | ||
parts = path.substr(root.length).split(sep) | ||
} else { | ||
@@ -880,2 +878,7 @@ // ".." is malicious without "root" | ||
var cacheControl = 'public, max-age=' + Math.floor(this._maxage / 1000) | ||
if (this._immutable) { | ||
cacheControl += ', immutable' | ||
} | ||
debug('cache-control %s', cacheControl) | ||
@@ -939,3 +942,4 @@ res.setHeader('Cache-Control', cacheControl) | ||
for (var i = 0; i < parts.length; i++) { | ||
if (parts[i][0] === '.') { | ||
var part = parts[i] | ||
if (part.length > 1 && part[0] === '.') { | ||
return true | ||
@@ -977,3 +981,4 @@ } | ||
'<pre>' + body + '</pre>\n' + | ||
'</body>\n' | ||
'</body>\n' + | ||
'<html>\n' | ||
} | ||
@@ -1014,2 +1019,22 @@ | ||
/** | ||
* Determine if emitter has listeners of a given type. | ||
* | ||
* The way to do this check is done three different ways in Node.js >= 0.8 | ||
* so this consolidates them into a minimal set using instance methods. | ||
* | ||
* @param {EventEmitter} emitter | ||
* @param {string} type | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function hasListeners (emitter, type) { | ||
var count = typeof emitter.listenerCount !== 'function' | ||
? emitter.listeners(type).length | ||
: emitter.listenerCount(type) | ||
return count > 0 | ||
} | ||
/** | ||
* Determine if the response headers have been sent. | ||
@@ -1016,0 +1041,0 @@ * |
{ | ||
"name": "send", | ||
"description": "Better streaming static file server with Range and conditional-GET support", | ||
"version": "0.15.6", | ||
"version": "0.16.0", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -27,3 +27,3 @@ "contributors": [ | ||
"http-errors": "~1.6.2", | ||
"mime": "1.3.4", | ||
"mime": "1.4.1", | ||
"ms": "2.0.0", | ||
@@ -37,6 +37,8 @@ "on-finished": "~2.3.0", | ||
"eslint": "3.19.0", | ||
"eslint-config-standard": "7.1.0", | ||
"eslint-config-standard": "10.2.1", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint-plugin-markdown": "1.0.0-beta.6", | ||
"eslint-plugin-node": "5.1.1", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "2.3.1", | ||
"eslint-plugin-standard": "3.0.1", | ||
"istanbul": "0.4.5", | ||
@@ -43,0 +45,0 @@ "mocha": "2.5.3", |
@@ -53,3 +53,3 @@ # send | ||
Enable or disable setting `Cache-Control` response header, defaults to | ||
true. Disabling this will ignore the `maxAge` option. | ||
true. Disabling this will ignore the `immutable` and `maxAge` options. | ||
@@ -90,2 +90,10 @@ ##### dotfiles | ||
##### immutable | ||
Enable or diable the `immutable` directive in the `Cache-Control` response | ||
header, defaults to `false`. If set to `true`, the `maxAge` option should | ||
also be specified to enable caching. The `immutable` directive will prevent | ||
supported clients from making conditional requests during the life of the | ||
`maxAge` option to check if the file has changed. | ||
##### index | ||
@@ -92,0 +100,0 @@ |
46354
933
310
11
+ Addedmime@1.4.1(transitive)
- Removedmime@1.3.4(transitive)
Updatedmime@1.4.1