send
Advanced tools
Comparing version 0.17.2 to 1.0.0-beta.1
@@ -0,1 +1,19 @@ | ||
1.0.0-beta.1 / 2022-02-04 | ||
========================= | ||
* Drop support for Node.js 0.8 | ||
* Remove `hidden` option -- use `dotfiles` option | ||
* Remove `from` alias to `root` -- use `root` directly | ||
* Remove `send.etag()` -- use `etag` in `options` | ||
* Remove `send.index()` -- use `index` in `options` | ||
* Remove `send.maxage()` -- use `maxAge` in `options` | ||
* Remove `send.root()` -- use `root` in `options` | ||
* Use `mime-types` for file to content type mapping -- removed `send.mime` | ||
* deps: debug@3.1.0 | ||
- Add `DEBUG_HIDE_DATE` environment variable | ||
- Change timer to per-namespace instead of global | ||
- Change non-TTY date format | ||
- Remove `DEBUG_FD` environment variable support | ||
- Support 256 namespace colors | ||
0.17.2 / 2021-12-11 | ||
@@ -2,0 +20,0 @@ =================== |
146
index.js
@@ -17,3 +17,2 @@ /*! | ||
var debug = require('debug')('send') | ||
var deprecate = require('depd')('send') | ||
var destroy = require('destroy') | ||
@@ -25,3 +24,3 @@ var encodeUrl = require('encodeurl') | ||
var fs = require('fs') | ||
var mime = require('mime') | ||
var mime = require('mime-types') | ||
var ms = require('ms') | ||
@@ -73,3 +72,2 @@ var onFinished = require('on-finished') | ||
module.exports = send | ||
module.exports.mime = mime | ||
@@ -128,13 +126,2 @@ /** | ||
this._hidden = Boolean(opts.hidden) | ||
if (opts.hidden !== undefined) { | ||
deprecate('hidden: use dotfiles: \'' + (this._hidden ? 'allow' : 'ignore') + '\' instead') | ||
} | ||
// legacy support | ||
if (opts.dotfiles === undefined) { | ||
this._dotfiles = undefined | ||
} | ||
this._extensions = opts.extensions !== undefined | ||
@@ -167,6 +154,2 @@ ? normalizeList(opts.extensions, 'extensions option') | ||
: null | ||
if (!this._root && opts.from) { | ||
this.from(opts.from) | ||
} | ||
} | ||
@@ -181,86 +164,2 @@ | ||
/** | ||
* Enable or disable etag generation. | ||
* | ||
* @param {Boolean} val | ||
* @return {SendStream} | ||
* @api public | ||
*/ | ||
SendStream.prototype.etag = deprecate.function(function etag (val) { | ||
this._etag = Boolean(val) | ||
debug('etag %s', this._etag) | ||
return this | ||
}, 'send.etag: pass etag as option') | ||
/** | ||
* Enable or disable "hidden" (dot) files. | ||
* | ||
* @param {Boolean} path | ||
* @return {SendStream} | ||
* @api public | ||
*/ | ||
SendStream.prototype.hidden = deprecate.function(function hidden (val) { | ||
this._hidden = Boolean(val) | ||
this._dotfiles = undefined | ||
debug('hidden %s', this._hidden) | ||
return this | ||
}, 'send.hidden: use dotfiles option') | ||
/** | ||
* Set index `paths`, set to a falsy | ||
* value to disable index support. | ||
* | ||
* @param {String|Boolean|Array} paths | ||
* @return {SendStream} | ||
* @api public | ||
*/ | ||
SendStream.prototype.index = deprecate.function(function index (paths) { | ||
var index = !paths ? [] : normalizeList(paths, 'paths argument') | ||
debug('index %o', paths) | ||
this._index = index | ||
return this | ||
}, 'send.index: pass index as option') | ||
/** | ||
* Set root `path`. | ||
* | ||
* @param {String} path | ||
* @return {SendStream} | ||
* @api public | ||
*/ | ||
SendStream.prototype.root = function root (path) { | ||
this._root = resolve(String(path)) | ||
debug('root %s', this._root) | ||
return this | ||
} | ||
SendStream.prototype.from = deprecate.function(SendStream.prototype.root, | ||
'send.from: pass root as option') | ||
SendStream.prototype.root = deprecate.function(SendStream.prototype.root, | ||
'send.root: pass root as option') | ||
/** | ||
* Set max-age to `maxAge`. | ||
* | ||
* @param {Number} maxAge | ||
* @return {SendStream} | ||
* @api public | ||
*/ | ||
SendStream.prototype.maxage = deprecate.function(function maxage (maxAge) { | ||
this._maxage = typeof maxAge === 'string' | ||
? ms(maxAge) | ||
: Number(maxAge) | ||
this._maxage = !isNaN(this._maxage) | ||
? Math.min(Math.max(0, this._maxage), MAX_MAXAGE) | ||
: 0 | ||
debug('max-age %d', this._maxage) | ||
return this | ||
}, 'send.maxage: pass maxAge as option') | ||
/** | ||
* Emit error with `status`. | ||
@@ -572,13 +471,4 @@ * | ||
if (containsDotFile(parts)) { | ||
var access = this._dotfiles | ||
// legacy support | ||
if (access === undefined) { | ||
access = parts[parts.length - 1][0] === '.' | ||
? (this._hidden ? 'allow' : 'ignore') | ||
: 'allow' | ||
} | ||
debug('%s dotfile "%s"', access, path) | ||
switch (access) { | ||
debug('%s dotfile "%s"', this._dotfiles, path) | ||
switch (this._dotfiles) { | ||
case 'allow': | ||
@@ -622,3 +512,3 @@ break | ||
if (headersSent(res)) { | ||
if (res.headersSent) { | ||
// impossible to send now | ||
@@ -846,13 +736,7 @@ this.headersAlreadySent() | ||
var type = mime.lookup(path) | ||
var ext = extname(path) | ||
var type = mime.contentType(ext) || 'application/octet-stream' | ||
if (!type) { | ||
debug('no content-type') | ||
return | ||
} | ||
var charset = mime.charsets.lookup(type) | ||
debug('content-type %s', type) | ||
res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : '')) | ||
res.setHeader('Content-Type', type) | ||
} | ||
@@ -1021,3 +905,3 @@ | ||
* | ||
* The way to do this check is done three different ways in Node.js >= 0.8 | ||
* The way to do this check is done three different ways in Node.js >= 0.10 | ||
* so this consolidates them into a minimal set using instance methods. | ||
@@ -1040,16 +924,2 @@ * | ||
/** | ||
* Determine if the response headers have been sent. | ||
* | ||
* @param {object} res | ||
* @returns {boolean} | ||
* @private | ||
*/ | ||
function headersSent (res) { | ||
return typeof res.headersSent !== 'boolean' | ||
? Boolean(res._header) | ||
: res.headersSent | ||
} | ||
/** | ||
* Normalize the index option into an array. | ||
@@ -1056,0 +926,0 @@ * |
{ | ||
"name": "send", | ||
"description": "Better streaming static file server with Range and conditional-GET support", | ||
"version": "0.17.2", | ||
"version": "1.0.0-beta.1", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -19,4 +19,3 @@ "contributors": [ | ||
"dependencies": { | ||
"debug": "2.6.9", | ||
"depd": "~1.1.2", | ||
"debug": "3.1.0", | ||
"destroy": "~1.0.4", | ||
@@ -28,3 +27,3 @@ "encodeurl": "~1.0.2", | ||
"http-errors": "1.8.1", | ||
"mime": "1.6.0", | ||
"mime-types": "~2.1.34", | ||
"ms": "2.1.3", | ||
@@ -55,3 +54,3 @@ "on-finished": "~2.3.0", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
"node": ">= 0.10" | ||
}, | ||
@@ -62,4 +61,5 @@ "scripts": { | ||
"test-ci": "nyc --reporter=lcov --reporter=text npm test", | ||
"test-cov": "nyc --reporter=html --reporter=text npm test" | ||
"test-cov": "nyc --reporter=html --reporter=text npm test", | ||
"version": "node scripts/version-history.js && git add HISTORY.md" | ||
} | ||
} |
@@ -136,11 +136,2 @@ # send | ||
### .mime | ||
The `mime` export is the global instance of of the | ||
[`mime` npm module](https://www.npmjs.com/package/mime). | ||
This is used to configure the MIME types that are associated with file extensions | ||
as well as other options for how to resolve the MIME type of a file (like the | ||
default type to use for an unknown file extension). | ||
## Error-handling | ||
@@ -214,2 +205,3 @@ | ||
```js | ||
var extname = require('path').extname | ||
var http = require('http') | ||
@@ -219,12 +211,13 @@ var parseUrl = require('parseurl') | ||
// Default unknown types to text/plain | ||
send.mime.default_type = 'text/plain' | ||
// Add a custom type | ||
send.mime.define({ | ||
'application/x-my-type': ['x-mt', 'x-mtt'] | ||
}) | ||
var server = http.createServer(function onRequest (req, res) { | ||
send(req, parseUrl(req).pathname, { root: '/www/public' }) | ||
.on('headers', function (res, path) { | ||
switch (extname(path)) { | ||
case '.x-mt': | ||
case '.x-mtt': | ||
// custom type for these extensions | ||
res.setHeader('Content-Type', 'application/x-my-type') | ||
break | ||
} | ||
}) | ||
.pipe(res) | ||
@@ -231,0 +224,0 @@ }) |
12
46102
830
321
+ Addedmime-types@~2.1.34
+ Addeddebug@3.1.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
- Removeddepd@~1.1.2
- Removedmime@1.6.0
- Removeddebug@2.6.9(transitive)
- Removedmime@1.6.0(transitive)
Updateddebug@3.1.0