Skip to content

Commit b5e395c

Browse files
committed
Merge tag '0.18.0' into 1.0
2 parents 00d54b6 + b69cbb3 commit b5e395c

File tree

9 files changed

+141
-45
lines changed

9 files changed

+141
-45
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
- Node.js 11.x
2626
- Node.js 12.x
2727
- Node.js 13.x
28+
- Node.js 14.x
29+
- Node.js 15.x
30+
- Node.js 16.x
31+
- Node.js 17.x
2832

2933
include:
3034
- name: Node.js 0.10
@@ -57,11 +61,11 @@ jobs:
5761

5862
- name: Node.js 6.x
5963
node-version: "6.17"
60-
npm-i: mocha@6.2.3 nyc@14.1.1
64+
npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6
6165

6266
- name: Node.js 7.x
6367
node-version: "7.10"
64-
npm-i: mocha@6.2.3 nyc@14.1.1
68+
npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6
6569

6670
- name: Node.js 8.x
6771
node-version: "8.16"
@@ -86,16 +90,16 @@ jobs:
8690
node-version: "13.14"
8791

8892
- name: Node.js 14.x
89-
node-version: "14.18"
93+
node-version: "14.19"
9094

9195
- name: Node.js 15.x
9296
node-version: "15.14"
9397

9498
- name: Node.js 16.x
95-
node-version: "16.13"
99+
node-version: "16.14"
96100

97101
- name: Node.js 17.x
98-
node-version: "17.2"
102+
node-version: "17.7"
99103

100104
steps:
101105
- uses: actions/checkout@v2

HISTORY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
- Remove `DEBUG_FD` environment variable support
1717
- Support 256 namespace colors
1818

19+
0.18.0 / 2022-03-23
20+
===================
21+
22+
* Fix emitted 416 error missing headers property
23+
* Limit the headers removed for 304 response
24+
* deps: depd@2.0.0
25+
- Replace internal `eval` usage with `Function` constructor
26+
- Use instance methods on `process` to check for listeners
27+
* deps: destroy@1.2.0
28+
* deps: http-errors@2.0.0
29+
- deps: depd@2.0.0
30+
- deps: statuses@2.0.1
31+
* deps: on-finished@2.4.1
32+
* deps: statuses@2.0.1
33+
1934
0.17.2 / 2021-12-11
2035
===================
2136

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(The MIT License)
22

33
Copyright (c) 2012 TJ Holowaychuk
4-
Copyright (c) 2014-2016 Douglas Christopher Wilson
4+
Copyright (c) 2014-2022 Douglas Christopher Wilson
55

66
Permission is hereby granted, free of charge, to any person obtaining
77
a copy of this software and associated documentation files (the

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ server.listen(3000)
311311
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/send
312312
[coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/send/master
313313
[coveralls-url]: https://coveralls.io/r/pillarjs/send?branch=master
314-
[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=ci
315-
[github-actions-ci-url]: https://github.com/pillarjs/send/actions?query=workflow%3Aci
314+
[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=linux
315+
[github-actions-ci-url]: https://github.com/pillarjs/send/actions/workflows/ci.yml
316316
[node-image]: https://badgen.net/npm/node/send
317317
[node-url]: https://nodejs.org/en/download/
318318
[npm-downloads-image]: https://badgen.net/npm/dm/send

SECURITY.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Security Policies and Procedures
2+
3+
## Reporting a Bug
4+
5+
The `send` team and community take all security bugs seriously. Thank you
6+
for improving the security of Express. We appreciate your efforts and
7+
responsible disclosure and will make every effort to acknowledge your
8+
contributions.
9+
10+
Report security bugs by emailing the current owner(s) of `send`. This information
11+
can be found in the npm registry using the command `npm owner ls send`.
12+
If unsure or unable to get the information from the above, open an issue
13+
in the [project issue tracker](https://github.com/pillarjs/send/issues)
14+
asking for the current contact information.
15+
16+
To ensure the timely response to your report, please ensure that the entirety
17+
of the report is contained within the email body and not solely behind a web
18+
link or an attachment.
19+
20+
At least one owner will acknowledge your email within 48 hours, and will send a
21+
more detailed response within 48 hours indicating the next steps in handling
22+
your report. After the initial reply to your report, the owners will
23+
endeavor to keep you informed of the progress towards a fix and full
24+
announcement, and may ask for additional information or guidance.

appveyor.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ environment:
1515
- nodejs_version: "11.15"
1616
- nodejs_version: "12.22"
1717
- nodejs_version: "13.14"
18-
- nodejs_version: "14.18"
18+
- nodejs_version: "14.19"
1919
- nodejs_version: "15.14"
20-
- nodejs_version: "16.13"
21-
- nodejs_version: "17.2"
20+
- nodejs_version: "16.14"
21+
- nodejs_version: "17.7"
2222
cache:
2323
- node_modules
2424
install:
@@ -61,10 +61,13 @@ install:
6161
# supertest for http calls
6262
# - use 2.0.0 for Node.js < 4
6363
# - use 3.4.2 for Node.js < 6
64+
# - use 6.1.6 for Node.js < 8
6465
if ([int]$env:nodejs_version.split(".")[0] -lt 4) {
6566
npm install --silent --save-dev supertest@2.0.0
6667
} elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) {
6768
npm install --silent --save-dev supertest@3.4.2
69+
} elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) {
70+
npm install --silent --save-dev supertest@6.1.6
6871
}
6972
# Update Node.js modules
7073
- ps: |

index.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* send
33
* Copyright(c) 2012 TJ Holowaychuk
4-
* Copyright(c) 2014-2016 Douglas Christopher Wilson
4+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
55
* MIT Licensed
66
*/
77

@@ -166,13 +166,11 @@ util.inherits(SendStream, Stream)
166166
SendStream.prototype.error = function error (status, err) {
167167
// emit if listeners instead of responding
168168
if (hasListeners(this, 'error')) {
169-
return this.emit('error', createError(status, err, {
170-
expose: false
171-
}))
169+
return this.emit('error', createHttpError(status, err))
172170
}
173171

174172
var res = this.res
175-
var msg = statuses[status] || String(status)
173+
var msg = statuses.message[status] || String(status)
176174
var doc = createHtmlDocument('Error', escapeHtml(msg))
177175

178176
// clear existing headers
@@ -248,21 +246,19 @@ SendStream.prototype.isPreconditionFailure = function isPreconditionFailure () {
248246
}
249247

250248
/**
251-
* Strip content-* header fields.
249+
* Strip various content header fields for a change in entity.
252250
*
253251
* @private
254252
*/
255253

256254
SendStream.prototype.removeContentHeaderFields = function removeContentHeaderFields () {
257255
var res = this.res
258-
var headers = getHeaderNames(res)
259256

260-
for (var i = 0; i < headers.length; i++) {
261-
var header = headers[i]
262-
if (header.substr(0, 8) === 'content-' && header !== 'content-location') {
263-
res.removeHeader(header)
264-
}
265-
}
257+
res.removeHeader('Content-Encoding')
258+
res.removeHeader('Content-Language')
259+
res.removeHeader('Content-Length')
260+
res.removeHeader('Content-Range')
261+
res.removeHeader('Content-Type')
266262
}
267263

268264
/**
@@ -677,8 +673,6 @@ SendStream.prototype.sendIndex = function sendIndex (path) {
677673
*/
678674

679675
SendStream.prototype.stream = function stream (path, options) {
680-
// TODO: this is all lame, refactor meeee
681-
var finished = false
682676
var self = this
683677
var res = this.res
684678

@@ -687,20 +681,18 @@ SendStream.prototype.stream = function stream (path, options) {
687681
this.emit('stream', stream)
688682
stream.pipe(res)
689683

690-
// response finished, done with the fd
691-
onFinished(res, function onfinished () {
692-
finished = true
693-
destroy(stream)
694-
})
684+
// cleanup
685+
function cleanup () {
686+
destroy(stream, true)
687+
}
695688

696-
// error handling code-smell
697-
stream.on('error', function onerror (err) {
698-
// request already finished
699-
if (finished) return
689+
// response finished, cleanup
690+
onFinished(res, cleanup)
700691

701-
// clean up stream
702-
finished = true
703-
destroy(stream)
692+
// error handling
693+
stream.on('error', function onerror (err) {
694+
// clean up stream early
695+
cleanup()
704696

705697
// error
706698
self.onStatError(err)
@@ -858,6 +850,24 @@ function createHtmlDocument (title, body) {
858850
'</html>\n'
859851
}
860852

853+
/**
854+
* Create a HttpError object from simple arguments.
855+
*
856+
* @param {number} status
857+
* @param {Error|object} err
858+
* @private
859+
*/
860+
861+
function createHttpError (status, err) {
862+
if (!err) {
863+
return createError(status)
864+
}
865+
866+
return err instanceof Error
867+
? createError(status, err, { expose: false })
868+
: createError(status, err)
869+
}
870+
861871
/**
862872
* decodeURIComponent.
863873
*

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,36 @@
1717
],
1818
"dependencies": {
1919
"debug": "3.1.0",
20-
"destroy": "~1.0.4",
20+
"destroy": "1.2.0",
2121
"encodeurl": "~1.0.2",
2222
"escape-html": "~1.0.3",
2323
"etag": "~1.8.1",
2424
"fresh": "0.5.2",
25-
"http-errors": "1.8.1",
25+
"http-errors": "2.0.0",
2626
"mime-types": "~2.1.34",
2727
"ms": "2.1.3",
28-
"on-finished": "~2.3.0",
28+
"on-finished": "2.4.1",
2929
"range-parser": "~1.2.1",
30-
"statuses": "~1.5.0"
30+
"statuses": "2.0.1"
3131
},
3232
"devDependencies": {
3333
"after": "0.8.2",
3434
"eslint": "7.32.0",
3535
"eslint-config-standard": "14.1.1",
36-
"eslint-plugin-import": "2.25.3",
36+
"eslint-plugin-import": "2.25.4",
3737
"eslint-plugin-markdown": "2.2.1",
3838
"eslint-plugin-node": "11.1.0",
3939
"eslint-plugin-promise": "5.2.0",
4040
"eslint-plugin-standard": "4.1.0",
41-
"mocha": "9.1.3",
41+
"mocha": "9.2.2",
4242
"nyc": "15.1.0",
43-
"supertest": "6.1.6"
43+
"supertest": "6.2.2"
4444
},
4545
"files": [
4646
"HISTORY.md",
4747
"LICENSE",
4848
"README.md",
49+
"SECURITY.md",
4950
"index.js"
5051
],
5152
"engines": {

test/send.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,27 @@ describe('send(file).pipe(res)', function () {
447447
})
448448
})
449449

450+
it('should not remove all Content-* headers', function (done) {
451+
var server = createServer({ root: fixtures }, function (req, res) {
452+
res.setHeader('Content-Location', 'http://localhost/name.txt')
453+
res.setHeader('Content-Security-Policy', 'default-src \'self\'')
454+
})
455+
456+
request(server)
457+
.get('/name.txt')
458+
.expect(200, function (err, res) {
459+
if (err) return done(err)
460+
request(server)
461+
.get('/name.txt')
462+
.set('If-None-Match', res.headers.etag)
463+
.expect(shouldNotHaveHeader('Content-Length'))
464+
.expect(shouldNotHaveHeader('Content-Type'))
465+
.expect('Content-Location', 'http://localhost/name.txt')
466+
.expect('Content-Security-Policy', 'default-src \'self\'')
467+
.expect(304, done)
468+
})
469+
})
470+
450471
describe('where "If-Match" is set', function () {
451472
it('should respond with 200 when "*"', function (done) {
452473
request(app)
@@ -650,6 +671,24 @@ describe('send(file).pipe(res)', function () {
650671
.expect('Content-Range', 'bytes */9')
651672
.expect(416, done)
652673
})
674+
675+
it('should emit error 416 with content-range header', function (done) {
676+
var server = http.createServer(function (req, res) {
677+
send(req, req.url, { root: fixtures })
678+
.on('error', function (err) {
679+
res.setHeader('X-Content-Range', err.headers['Content-Range'])
680+
res.statusCode = err.statusCode
681+
res.end(err.message)
682+
})
683+
.pipe(res)
684+
})
685+
686+
request(server)
687+
.get('/nums.txt')
688+
.set('Range', 'bytes=9-50')
689+
.expect('X-Content-Range', 'bytes */9')
690+
.expect(416, done)
691+
})
653692
})
654693

655694
describe('when syntactically invalid', function () {

0 commit comments

Comments
 (0)