From 175bd7db07e9e45c492ac143c786d343f1fbe1bb Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 29 Dec 2021 20:31:35 -0500 Subject: [PATCH 01/25] build: fix run names in Github Actions --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f80ad3..b0745b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,10 @@ jobs: - Node.js 11.x - Node.js 12.x - Node.js 13.x + - Node.js 14.x + - Node.js 15.x + - Node.js 16.x + - Node.js 17.x include: - name: Node.js 0.8 From ab8aaf2d61c15c86b0698d0735f7b23780cc83f1 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 24 Jan 2022 19:33:58 -0500 Subject: [PATCH 02/25] build: Node.js@17.4 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0745b5..fde6028 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.13" - name: Node.js 17.x - node-version: "17.2" + node-version: "17.4" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index d577cca..e27c256 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: - nodejs_version: "14.18" - nodejs_version: "15.14" - nodejs_version: "16.13" - - nodejs_version: "17.2" + - nodejs_version: "17.4" cache: - node_modules install: From 2fd0b0e8d1e92542699563b4909d10ab3ea747da Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 24 Jan 2022 19:39:53 -0500 Subject: [PATCH 03/25] build: eslint-plugin-import@2.25.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f58140c..80d4dfd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "after": "0.8.2", "eslint": "7.32.0", "eslint-config-standard": "14.1.1", - "eslint-plugin-import": "2.25.3", + "eslint-plugin-import": "2.25.4", "eslint-plugin-markdown": "2.2.1", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "5.2.0", From 336cedfdc98e776eb7dadad648c9fefcaf8297eb Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 25 Jan 2022 01:43:51 -0500 Subject: [PATCH 04/25] build: mocha@9.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80d4dfd..7bdb2bb 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "5.2.0", "eslint-plugin-standard": "4.1.0", - "mocha": "9.1.3", + "mocha": "9.2.0", "nyc": "15.1.0", "supertest": "6.1.6" }, From 1ae51cd960ad1324da214e5a7ff4e35fd3e02baa Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 26 Jan 2022 20:05:00 -0500 Subject: [PATCH 05/25] build: supertest@6.2.2 --- .github/workflows/ci.yml | 4 ++-- appveyor.yml | 3 +++ package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fde6028..165a6d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,11 +67,11 @@ jobs: - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.3 nyc@14.1.1 + npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6 - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.3 nyc@14.1.1 + npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6 - name: Node.js 8.x node-version: "8.16" diff --git a/appveyor.yml b/appveyor.yml index e27c256..47ea17e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -61,10 +61,13 @@ install: # supertest for http calls # - use 2.0.0 for Node.js < 4 # - use 3.4.2 for Node.js < 6 + # - use 6.1.6 for Node.js < 8 if ([int]$env:nodejs_version.split(".")[0] -lt 4) { npm install --silent --save-dev supertest@2.0.0 } elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) { npm install --silent --save-dev supertest@3.4.2 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) { + npm install --silent --save-dev supertest@6.1.6 } # Update Node.js modules - ps: | diff --git a/package.json b/package.json index 7bdb2bb..3c968b4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-standard": "4.1.0", "mocha": "9.2.0", "nyc": "15.1.0", - "supertest": "6.1.6" + "supertest": "6.2.2" }, "files": [ "HISTORY.md", From 879f19d92d784b45f611ced9f045f5ea3888f450 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 28 Jan 2022 18:58:00 -0500 Subject: [PATCH 06/25] build: Node.js@14.19 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 165a6d7..7f7527f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.18" + node-version: "14.19" - name: Node.js 15.x node-version: "15.14" diff --git a/appveyor.yml b/appveyor.yml index 47ea17e..06133a8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ environment: - nodejs_version: "11.15" - nodejs_version: "12.22" - nodejs_version: "13.14" - - nodejs_version: "14.18" + - nodejs_version: "14.19" - nodejs_version: "15.14" - nodejs_version: "16.13" - nodejs_version: "17.4" From 4eaab36637db751b90202eae4fb8d02567ef3a6a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 6 Feb 2022 22:08:00 -0500 Subject: [PATCH 07/25] deps: destroy@1.1.0 --- HISTORY.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 8aa3ab3..597559d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * deps: destroy@1.1.0 + 0.17.2 / 2021-12-11 =================== diff --git a/package.json b/package.json index 3c968b4..47dad5a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dependencies": { "debug": "2.6.9", "depd": "~1.1.2", - "destroy": "~1.0.4", + "destroy": "1.1.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", From f266d738a5c8e4228e23cda107988c8d471f3547 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 23:51:00 -0500 Subject: [PATCH 08/25] build: Node.js@16.14 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f7527f..0ec3f75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,7 +102,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.13" + node-version: "16.14" - name: Node.js 17.x node-version: "17.4" diff --git a/appveyor.yml b/appveyor.yml index 06133a8..8be8527 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ environment: - nodejs_version: "13.14" - nodejs_version: "14.19" - nodejs_version: "15.14" - - nodejs_version: "16.13" + - nodejs_version: "16.14" - nodejs_version: "17.4" cache: - node_modules From 5a63b710990d60f111510b7585882e85abef15f2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 23:54:00 -0500 Subject: [PATCH 09/25] build: Node.js@17.5 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ec3f75..3de5ea1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.14" - name: Node.js 17.x - node-version: "17.4" + node-version: "17.5" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index 8be8527..08e84a5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: - nodejs_version: "14.19" - nodejs_version: "15.14" - nodejs_version: "16.14" - - nodejs_version: "17.4" + - nodejs_version: "17.5" cache: - node_modules install: From ab2a59d874d7b3a45bd219a2fba024bc15752563 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 25 Feb 2022 21:37:00 -0500 Subject: [PATCH 10/25] build: mocha@9.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47dad5a..ac83394 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "5.2.0", "eslint-plugin-standard": "4.1.0", - "mocha": "9.2.0", + "mocha": "9.2.1", "nyc": "15.1.0", "supertest": "6.2.2" }, From a966ace3714af65f9e5a873f6082193f4c8d1bef Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 26 Feb 2022 00:17:00 -0500 Subject: [PATCH 11/25] build: Node.js@17.6 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3de5ea1..9b89db3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.14" - name: Node.js 17.x - node-version: "17.5" + node-version: "17.6" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index 08e84a5..5fcc217 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: - nodejs_version: "14.19" - nodejs_version: "15.14" - nodejs_version: "16.14" - - nodejs_version: "17.5" + - nodejs_version: "17.6" cache: - node_modules install: From 53f0ab476145670a9bdd3dc722ab2fdc8d358fc6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Mar 2022 00:17:00 -0500 Subject: [PATCH 12/25] deps: destroy@1.1.1 --- HISTORY.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 597559d..26eeede 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,7 +1,7 @@ unreleased ========== - * deps: destroy@1.1.0 + * deps: destroy@1.1.1 0.17.2 / 2021-12-11 =================== diff --git a/package.json b/package.json index ac83394..b16826c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dependencies": { "debug": "2.6.9", "depd": "~1.1.2", - "destroy": "1.1.0", + "destroy": "1.1.1", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", From 24b4af2eed289aca8869d875772de725b6cacbd6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Mar 2022 00:39:00 -0500 Subject: [PATCH 13/25] Fix emitted 416 error missing headers property --- HISTORY.md | 1 + index.js | 22 +++++++++++++++++++--- test/send.js | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 26eeede..9f4665a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ========== + * Fix emitted 416 error missing headers property * deps: destroy@1.1.1 0.17.2 / 2021-12-11 diff --git a/index.js b/index.js index 06d7507..eba4a37 100644 --- a/index.js +++ b/index.js @@ -267,9 +267,7 @@ SendStream.prototype.maxage = deprecate.function(function maxage (maxAge) { SendStream.prototype.error = function error (status, err) { // emit if listeners instead of responding if (hasListeners(this, 'error')) { - return this.emit('error', createError(status, err, { - expose: false - })) + return this.emit('error', createHttpError(status, err)) } var res = this.res @@ -974,6 +972,24 @@ function createHtmlDocument (title, body) { '\n' } +/** + * Create a HttpError object from simple arguments. + * + * @param {number} status + * @param {Error|object} err + * @private + */ + +function createHttpError (status, err) { + if (!err) { + return createError(status) + } + + return err instanceof Error + ? createError(status, err, { expose: false }) + : createError(status, err) +} + /** * decodeURIComponent. * diff --git a/test/send.js b/test/send.js index 4daacfa..04a68b6 100644 --- a/test/send.js +++ b/test/send.js @@ -643,6 +643,24 @@ describe('send(file).pipe(res)', function () { .expect('Content-Range', 'bytes */9') .expect(416, done) }) + + it('should emit error 416 with content-range header', function (done) { + var server = http.createServer(function (req, res) { + send(req, req.url, { root: fixtures }) + .on('error', function (err) { + res.setHeader('X-Content-Range', err.headers['Content-Range']) + res.statusCode = err.statusCode + res.end(err.message) + }) + .pipe(res) + }) + + request(server) + .get('/nums.txt') + .set('Range', 'bytes=9-50') + .expect('X-Content-Range', 'bytes */9') + .expect(416, done) + }) }) describe('when syntactically invalid', function () { From 21f0fbbd3c3bc0250ad4938194cccc599a0bb39b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 5 Mar 2022 21:33:00 -0500 Subject: [PATCH 14/25] deps: http-errors@2.0.0 --- HISTORY.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 9f4665a..7c7f051 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,9 @@ unreleased * Fix emitted 416 error missing headers property * deps: destroy@1.1.1 + * deps: http-errors@2.0.0 + - deps: depd@2.0.0 + - deps: statuses@2.0.1 0.17.2 / 2021-12-11 =================== diff --git a/package.json b/package.json index b16826c..9967f8e 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "escape-html": "~1.0.3", "etag": "~1.8.1", "fresh": "0.5.2", - "http-errors": "1.8.1", + "http-errors": "2.0.0", "mime": "1.6.0", "ms": "2.1.3", "on-finished": "~2.3.0", From 1495ddae1565528636789010e66483e07d2d6620 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 5 Mar 2022 21:43:00 -0500 Subject: [PATCH 15/25] deps: depd@2.0.0 --- HISTORY.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 7c7f051..d779d5d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,9 @@ unreleased ========== * Fix emitted 416 error missing headers property + * deps: depd@2.0.0 + - Replace internal `eval` usage with `Function` constructor + - Use instance methods on `process` to check for listeners * deps: destroy@1.1.1 * deps: http-errors@2.0.0 - deps: depd@2.0.0 diff --git a/package.json b/package.json index 9967f8e..8317cdb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ ], "dependencies": { "debug": "2.6.9", - "depd": "~1.1.2", + "depd": "2.0.0", "destroy": "1.1.1", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", From f3cf8a9506618e08f80bb8476366604c7f2db0c1 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 8 Mar 2022 01:21:00 -0500 Subject: [PATCH 16/25] deps: statuses@2.0.1 --- HISTORY.md | 1 + index.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d779d5d..f2b24ad 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ unreleased * deps: http-errors@2.0.0 - deps: depd@2.0.0 - deps: statuses@2.0.1 + * deps: statuses@2.0.1 0.17.2 / 2021-12-11 =================== diff --git a/index.js b/index.js index eba4a37..fbdecf3 100644 --- a/index.js +++ b/index.js @@ -271,7 +271,7 @@ SendStream.prototype.error = function error (status, err) { } var res = this.res - var msg = statuses[status] || String(status) + var msg = statuses.message[status] || String(status) var doc = createHtmlDocument('Error', escapeHtml(msg)) // clear existing headers diff --git a/package.json b/package.json index 8317cdb..03e1626 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "ms": "2.1.3", "on-finished": "~2.3.0", "range-parser": "~1.2.1", - "statuses": "~1.5.0" + "statuses": "2.0.1" }, "devDependencies": { "after": "0.8.2", From 53642192064d636964e4dbf46268dd79b7635853 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Mar 2022 23:11:00 -0400 Subject: [PATCH 17/25] build: mocha@9.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 03e1626..3e19db0 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "5.2.0", "eslint-plugin-standard": "4.1.0", - "mocha": "9.2.1", + "mocha": "9.2.2", "nyc": "15.1.0", "supertest": "6.2.2" }, From 8055f787fee1a189b23a27e67dcc185dfe26bac2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Mar 2022 23:13:00 -0400 Subject: [PATCH 18/25] build: Node.js@17.7 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b89db3..6c5b941 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.14" - name: Node.js 17.x - node-version: "17.6" + node-version: "17.7" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index 5fcc217..1332a99 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: - nodejs_version: "14.19" - nodejs_version: "15.14" - nodejs_version: "16.14" - - nodejs_version: "17.6" + - nodejs_version: "17.7" cache: - node_modules install: From 6060bdaf1a8684deec45704ad4e4b163d910f6fa Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 19 Mar 2022 23:11:00 -0400 Subject: [PATCH 19/25] deps: on-finished@2.4.1 --- HISTORY.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index f2b24ad..37b0d3a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ unreleased * deps: http-errors@2.0.0 - deps: depd@2.0.0 - deps: statuses@2.0.1 + * deps: on-finished@2.4.1 * deps: statuses@2.0.1 0.17.2 / 2021-12-11 diff --git a/package.json b/package.json index 3e19db0..0a2bab3 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "http-errors": "2.0.0", "mime": "1.6.0", "ms": "2.1.3", - "on-finished": "~2.3.0", + "on-finished": "2.4.1", "range-parser": "~1.2.1", "statuses": "2.0.1" }, From aee1a657be9fdf558ce3448c6a908227e15f0645 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 22:35:28 -0400 Subject: [PATCH 20/25] deps: destroy@1.2.0 --- HISTORY.md | 2 +- index.js | 24 ++++++++++-------------- package.json | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 37b0d3a..581fa89 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,7 +5,7 @@ unreleased * deps: depd@2.0.0 - Replace internal `eval` usage with `Function` constructor - Use instance methods on `process` to check for listeners - * deps: destroy@1.1.1 + * deps: destroy@1.2.0 * deps: http-errors@2.0.0 - deps: depd@2.0.0 - deps: statuses@2.0.1 diff --git a/index.js b/index.js index fbdecf3..5ba20d9 100644 --- a/index.js +++ b/index.js @@ -785,8 +785,6 @@ SendStream.prototype.sendIndex = function sendIndex (path) { */ SendStream.prototype.stream = function stream (path, options) { - // TODO: this is all lame, refactor meeee - var finished = false var self = this var res = this.res @@ -795,20 +793,18 @@ SendStream.prototype.stream = function stream (path, options) { this.emit('stream', stream) stream.pipe(res) - // response finished, done with the fd - onFinished(res, function onfinished () { - finished = true - destroy(stream) - }) + // cleanup + function cleanup () { + destroy(stream, true) + } - // error handling code-smell - stream.on('error', function onerror (err) { - // request already finished - if (finished) return + // response finished, cleanup + onFinished(res, cleanup) - // clean up stream - finished = true - destroy(stream) + // error handling + stream.on('error', function onerror (err) { + // clean up stream early + cleanup() // error self.onStatError(err) diff --git a/package.json b/package.json index 0a2bab3..98d1a75 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dependencies": { "debug": "2.6.9", "depd": "2.0.0", - "destroy": "1.1.1", + "destroy": "1.2.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1", From fed09ff7dd5b24470fadaa6626b5db1667cccec6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 22:36:02 -0400 Subject: [PATCH 21/25] docs: update copyright --- LICENSE | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 4aa69e8..b6ea1c1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ (The MIT License) Copyright (c) 2012 TJ Holowaychuk -Copyright (c) 2014-2016 Douglas Christopher Wilson +Copyright (c) 2014-2022 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/index.js b/index.js index 5ba20d9..e0441da 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ /*! * send * Copyright(c) 2012 TJ Holowaychuk - * Copyright(c) 2014-2016 Douglas Christopher Wilson + * Copyright(c) 2014-2022 Douglas Christopher Wilson * MIT Licensed */ From b690ba4bd149d20fa6687ee6298fb6aede5b21d7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 22:47:39 -0400 Subject: [PATCH 22/25] docs: fix linux build badge link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc1d3a1..fadf838 100644 --- a/README.md +++ b/README.md @@ -318,8 +318,8 @@ server.listen(3000) [appveyor-url]: https://ci.appveyor.com/project/dougwilson/send [coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/send/master [coveralls-url]: https://coveralls.io/r/pillarjs/send?branch=master -[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=ci -[github-actions-ci-url]: https://github.com/pillarjs/send/actions?query=workflow%3Aci +[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=linux +[github-actions-ci-url]: https://github.com/pillarjs/send/actions/workflows/ci.yml [node-image]: https://badgen.net/npm/node/send [node-url]: https://nodejs.org/en/download/ [npm-downloads-image]: https://badgen.net/npm/dm/send From 706d6ddf0d3c8a9248fc1edbc3ff60bbc6ad7b93 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 23:07:27 -0400 Subject: [PATCH 23/25] docs: add security policy --- SECURITY.md | 24 ++++++++++++++++++++++++ package.json | 1 + 2 files changed, 25 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..46b48f7 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,24 @@ +# Security Policies and Procedures + +## Reporting a Bug + +The `send` team and community take all security bugs seriously. Thank you +for improving the security of Express. We appreciate your efforts and +responsible disclosure and will make every effort to acknowledge your +contributions. + +Report security bugs by emailing the current owner(s) of `send`. This information +can be found in the npm registry using the command `npm owner ls send`. +If unsure or unable to get the information from the above, open an issue +in the [project issue tracker](https://github.com/pillarjs/send/issues) +asking for the current contact information. + +To ensure the timely response to your report, please ensure that the entirety +of the report is contained within the email body and not solely behind a web +link or an attachment. + +At least one owner will acknowledge your email within 48 hours, and will send a +more detailed response within 48 hours indicating the next steps in handling +your report. After the initial reply to your report, the owners will +endeavor to keep you informed of the progress towards a fix and full +announcement, and may ask for additional information or guidance. diff --git a/package.json b/package.json index 98d1a75..124f111 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "HISTORY.md", "LICENSE", "README.md", + "SECURITY.md", "index.js" ], "engines": { From f53edbb7f4f7ebdd936d3d714d84d52f2d3d00f3 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 23:43:48 -0400 Subject: [PATCH 24/25] Limit the headers removed for 304 response closes #204 --- HISTORY.md | 1 + index.js | 14 ++++++-------- test/send.js | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 581fa89..9fd925f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ unreleased ========== * Fix emitted 416 error missing headers property + * Limit the headers removed for 304 response * deps: depd@2.0.0 - Replace internal `eval` usage with `Function` constructor - Use instance methods on `process` to check for listeners diff --git a/index.js b/index.js index e0441da..89afd7e 100644 --- a/index.js +++ b/index.js @@ -347,21 +347,19 @@ SendStream.prototype.isPreconditionFailure = function isPreconditionFailure () { } /** - * Strip content-* header fields. + * Strip various content header fields for a change in entity. * * @private */ SendStream.prototype.removeContentHeaderFields = function removeContentHeaderFields () { var res = this.res - var headers = getHeaderNames(res) - for (var i = 0; i < headers.length; i++) { - var header = headers[i] - if (header.substr(0, 8) === 'content-' && header !== 'content-location') { - res.removeHeader(header) - } - } + res.removeHeader('Content-Encoding') + res.removeHeader('Content-Language') + res.removeHeader('Content-Length') + res.removeHeader('Content-Range') + res.removeHeader('Content-Type') } /** diff --git a/test/send.js b/test/send.js index 04a68b6..d419f8f 100644 --- a/test/send.js +++ b/test/send.js @@ -440,6 +440,27 @@ describe('send(file).pipe(res)', function () { }) }) + it('should not remove all Content-* headers', function (done) { + var server = createServer({ root: fixtures }, function (req, res) { + res.setHeader('Content-Location', 'http://localhost/name.txt') + res.setHeader('Content-Security-Policy', 'default-src \'self\'') + }) + + request(server) + .get('/name.txt') + .expect(200, function (err, res) { + if (err) return done(err) + request(server) + .get('/name.txt') + .set('If-None-Match', res.headers.etag) + .expect(shouldNotHaveHeader('Content-Length')) + .expect(shouldNotHaveHeader('Content-Type')) + .expect('Content-Location', 'http://localhost/name.txt') + .expect('Content-Security-Policy', 'default-src \'self\'') + .expect(304, done) + }) + }) + describe('where "If-Match" is set', function () { it('should respond with 200 when "*"', function (done) { request(app) From b69cbb3dc4c09c37917d08a4c13fcd1bac97ade5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 23 Mar 2022 22:53:50 -0400 Subject: [PATCH 25/25] 0.18.0 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9fd925f..a739774 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +0.18.0 / 2022-03-23 +=================== * Fix emitted 416 error missing headers property * Limit the headers removed for 304 response diff --git a/package.json b/package.json index 124f111..7f269d5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "send", "description": "Better streaming static file server with Range and conditional-GET support", - "version": "0.17.2", + "version": "0.18.0", "author": "TJ Holowaychuk ", "contributors": [ "Douglas Christopher Wilson ",