http: OutgoingMessage change writable after end · nodejs/node@63aee3b · GitHub
Skip to content

Commit 63aee3b

Browse files
Kasheraddaleax
authored andcommitted
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. PR-URL: #14024 Fixes: #14023 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent 6f13d7d commit 63aee3b

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

lib/_http_outgoing.js

Lines changed: 1 addition & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
// Verify that after calling end() on an `OutgoingMessage` (or a type that
7+
// inherits from `OutgoingMessage`), its `writable` property is set to false.
8+
9+
const server = http.createServer(common.mustCall(function(req, res) {
10+
assert.strictEqual(res.writable, true);
11+
assert.strictEqual(res.finished, false);
12+
res.end();
13+
assert.strictEqual(res.writable, false);
14+
assert.strictEqual(res.finished, true);
15+
16+
server.close();
17+
}));
18+
19+
server.listen(0);
20+
21+
server.on('listening', common.mustCall(function() {
22+
const clientRequest = http.request({
23+
port: server.address().port,
24+
method: 'GET',
25+
path: '/'
26+
});
27+
28+
assert.strictEqual(clientRequest.writable, true);
29+
clientRequest.end();
30+
assert.strictEqual(clientRequest.writable, false);
31+
}));
Lines changed: 39 additions & 0 deletions

0 commit comments

Comments
 (0)