-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: OutgoingMessage change writable after end
When an OutgoingMessage is closed (for example, using the `end` method), its 'writable' property should be changed to false - since it is not writable anymore. The 'writable' property should have the opposite value of the 'finished' property.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
assert(res.writable, 'Res should be writable when it is received \ | ||
and opened.'); | ||
assert(!res.finished, 'Res shouldn\'t be finished when it is received \ | ||
and opened.'); | ||
res.end(); | ||
assert(!res.writable, 'Res shouldn\'t be writable after it was closed.'); | ||
assert(res.finished, 'Res should be finished after it was closed.'); | ||
|
||
server.close(); | ||
})); | ||
|
||
server.listen(0); | ||
|
||
server.on('listening', common.mustCall(function() { | ||
http.request({ | ||
port: server.address().port, | ||
method: 'GET', | ||
path: '/' | ||
}).end(); | ||
})); |
35 changes: 35 additions & 0 deletions
35
test/parallel/test-pipe-outgoing-message-data-emitted-after-ended.js
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,35 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
const OutgoingMessage = require('_http_outgoing').OutgoingMessage; | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
console.log('Got a request, piping an OutgoingMessage to it.'); | ||
const outgointMessage = new OutgoingMessage(); | ||
outgointMessage.pipe(res); | ||
|
||
setTimeout(() => { | ||
console.log('Closing response.'); | ||
res.end(); | ||
outgointMessage.emit('data', 'some data'); | ||
|
||
// If we got here - 'write after end' wasn't raised and the test passed. | ||
setTimeout(() => server.close(), 10); | ||
}, 10); | ||
|
||
setInterval(() => { | ||
console.log('Emitting some data to outgointMessage'); | ||
outgointMessage.emit('data', 'some data'); | ||
}, 1).unref(); | ||
|
||
})); | ||
|
||
server.listen(0); | ||
|
||
server.on('listening', common.mustCall(function() { | ||
http.request({ | ||
port: server.address().port, | ||
method: 'GET', | ||
path: '/' | ||
}).end(); | ||
})); |