Skip to content
Permalink
Browse files

http: add missing stream-like properties to OutgoingMessage

PR-URL: #29018
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
ronag authored and targos committed Aug 6, 2019
1 parent e543d35 commit 16e001112c31c0fca3dfb3ea6ee465cbf2c917aa
Showing with 72 additions and 1 deletion.
  1. +19 −1 lib/_http_outgoing.js
  2. +53 −0 test/parallel/test-http-outgoing-properties.js
@@ -112,7 +112,7 @@ Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
Object.setPrototypeOf(OutgoingMessage, Stream);

Object.defineProperty(OutgoingMessage.prototype, 'writableFinished', {
get: function() {
get() {
return (
this.finished &&
this.outputSize === 0 &&
@@ -121,6 +121,24 @@ Object.defineProperty(OutgoingMessage.prototype, 'writableFinished', {
}
});

Object.defineProperty(OutgoingMessage.prototype, 'writableObjectMode', {
get() {
return false;
}
});

Object.defineProperty(OutgoingMessage.prototype, 'writableLength', {
get() {
return this.outputSize + (this.socket ? this.socket.writableLength : 0);
}
});

Object.defineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
get() {
return this.socket ? this.socket.writableHighWaterMark : HIGH_WATER_MARK;
}
});

Object.defineProperty(OutgoingMessage.prototype, '_headers', {
get: internalUtil.deprecate(function() {
return this.getHeaders();
@@ -0,0 +1,53 @@
'use strict';
const common = require('../common');
const assert = require('assert');

const http = require('http');
const OutgoingMessage = http.OutgoingMessage;

{
const msg = new OutgoingMessage();
assert.strictEqual(msg.writableObjectMode, false);
}

{
const msg = new OutgoingMessage();
assert(msg.writableHighWaterMark > 0);
}

{
const server = http.createServer(common.mustCall(function(req, res) {
const hwm = req.socket.writableHighWaterMark;
assert.strictEqual(res.writableHighWaterMark, hwm);

assert.strictEqual(res.writableLength, 0);
res.write('');
const len = res.writableLength;
res.write('asd');
assert.strictEqual(res.writableLength, len + 8);
res.end();
res.on('finish', common.mustCall(() => {
assert.strictEqual(res.writableLength, 0);
server.close();
}));
}));

server.listen(0);

server.on('listening', common.mustCall(function() {
const clientRequest = http.request({
port: server.address().port,
method: 'GET',
path: '/'
});
clientRequest.end();
}));
}

{
const msg = new OutgoingMessage();
msg._implicitHeader = function() {};
assert.strictEqual(msg.writableLength, 0);
msg.write('asd');
assert.strictEqual(msg.writableLength, 7);
}

0 comments on commit 16e0011

Please sign in to comment.
You can’t perform that action at this time.