-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: emit 'error' on aborted client response
Client responses aka. IncomingMessage emits 'aborted' instead of 'error' which causes confusion when the object is used as a regular stream, i.e. if functions working on streams are passed a client response object they might not work properly unless they take this into account. Refs: nodejs/web-server-frameworks#41 Fixes: #28172
- Loading branch information
Showing
7 changed files
with
67 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
const assert = require('assert'); | ||
|
||
let serverRes; | ||
const server = http.Server(function(req, res) { | ||
res.write('Part of my res.'); | ||
serverRes = res; | ||
}); | ||
{ | ||
let serverRes; | ||
const server = http.Server(function(req, res) { | ||
res.write('Part of my res.'); | ||
serverRes = res; | ||
}); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
http.get({ | ||
port: this.address().port, | ||
headers: { connection: 'keep-alive' } | ||
}, common.mustCall(function(res) { | ||
server.close(); | ||
serverRes.destroy(); | ||
res.on('aborted', common.mustCall()); | ||
server.listen(0, common.mustCall(function() { | ||
http.get({ | ||
port: this.address().port, | ||
headers: { connection: 'keep-alive' } | ||
}, common.mustCall(function(res) { | ||
server.close(); | ||
serverRes.destroy(); | ||
res.on('aborted', common.mustCall()); | ||
res.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.code, 'ECONNRESET'); | ||
})); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
{ | ||
// Don't crash of no 'error' handler. | ||
let serverRes; | ||
const server = http.Server(function(req, res) { | ||
res.write('Part of my res.'); | ||
serverRes = res; | ||
}); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
http.get({ | ||
port: this.address().port, | ||
headers: { connection: 'keep-alive' } | ||
}, common.mustCall(function(res) { | ||
server.close(); | ||
serverRes.destroy(); | ||
res.on('aborted', common.mustCall()); | ||
})); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters