This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: emit close as the last event in the client
Emit close event after all other events in the client, e.g. error will be emitted before close. PR-URL: nodejs/node#15588 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This test ensures that the `'close'` event is emitted after the `'error'` | ||
// event when a request is made and the socket is closed before we started to | ||
// receive a response. | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer(common.mustNotCall()); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const req = http.get({ port: server.address().port }, common.mustNotCall()); | ||
let errorEmitted = false; | ||
|
||
req.on('error', (err) => { | ||
errorEmitted = true; | ||
assert.strictEqual(err.constructor, Error); | ||
assert.strictEqual(err.message, 'socket hang up'); | ||
assert.strictEqual(err.code, 'ECONNRESET'); | ||
}); | ||
|
||
req.on('close', common.mustCall(() => { | ||
assert.strictEqual(errorEmitted, true); | ||
server.close(); | ||
})); | ||
|
||
req.destroy(); | ||
})); |