Comparing version 4.0.1 to 4.0.2
@@ -0,1 +1,5 @@ | ||
2019/04/14 Version 4.0.2 | ||
- Add dependency for is-finished library | ||
- Fixes for edge cases around closed/finished streams | ||
2019/04/12 Version 4.0.1 | ||
@@ -2,0 +6,0 @@ - Fix file descriptor leak from upstream response closing |
@@ -15,2 +15,3 @@ #! /usr/bin/env node | ||
const optsParser = require('./ecstatic/opts'); | ||
const onFinished = require('on-finished'); | ||
@@ -245,2 +246,6 @@ let ecstatic = null; | ||
function serve(stat) { | ||
if (onFinished.isFinished(res)) { | ||
return; | ||
} | ||
// Do a MIME lookup, fall back to octet-stream and handle gzip | ||
@@ -256,3 +261,2 @@ // and brotli special case. | ||
let cacheControl = cache; | ||
let stream = null; | ||
if (contentType) { | ||
@@ -293,3 +297,2 @@ charSet = mime.lookupCharset(contentType); | ||
const chunksize = (end - start) + 1; | ||
let fstream = null; | ||
@@ -301,9 +304,2 @@ if (start > end || isNaN(start) || isNaN(end)) { | ||
fstream = fs.createReadStream(file, { start, end }); | ||
fstream.on('error', (err) => { | ||
status['500'](res, next, { error: err }); | ||
}); | ||
res.on('close', () => { | ||
fstream.destroy(); | ||
}); | ||
res.writeHead(206, { | ||
@@ -318,3 +314,12 @@ 'Content-Range': `bytes ${start}-${end}/${total}`, | ||
}); | ||
fstream.pipe(res); | ||
const stream = fs | ||
.createReadStream(file, { start, end }) | ||
.on('error', (err) => { | ||
status['500'](res, next, { error: err }); | ||
}) | ||
.pipe(res); | ||
onFinished(res, () => { | ||
stream.destroy(); | ||
}); | ||
return; | ||
@@ -347,7 +352,10 @@ } | ||
stream = fs.createReadStream(file); | ||
stream.pipe(res); | ||
stream.on('error', (err) => { | ||
status['500'](res, next, { error: err }); | ||
const stream = fs | ||
.createReadStream(file) | ||
.on('error', (err) => { | ||
status['500'](res, next, { error: err }); | ||
}) | ||
.pipe(res); | ||
onFinished(res, () => { | ||
stream.destroy(); | ||
}); | ||
@@ -354,0 +362,0 @@ res.on('close', () => { |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"homepage": "https://github.com/jfhbrook/node-ecstatic", | ||
@@ -33,2 +33,3 @@ "repository": { | ||
"minimist": "^1.1.0", | ||
"on-finished": "^2.3.0", | ||
"url-join": "^4.0.0" | ||
@@ -35,0 +36,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
317136
1330
6
+ Addedon-finished@^2.3.0
+ Addedee-first@1.1.1(transitive)
+ Addedon-finished@2.4.1(transitive)