summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-06 15:30:06 +0200
committerRich Trott <rtrott@gmail.com>2019-08-10 18:59:10 -0700
commitbd857084de75815d0d60d4a7dd4897dfc9e6cdec (patch)
tree3646acb263fe3f4d47f47a5907170f6be46dc060
parent83495e778319603c3ed61e31d37dc9715df14329 (diff)
downloadandroid-node-v8-bd857084de75815d0d60d4a7dd4897dfc9e6cdec.tar.gz
android-node-v8-bd857084de75815d0d60d4a7dd4897dfc9e6cdec.tar.bz2
android-node-v8-bd857084de75815d0d60d4a7dd4897dfc9e6cdec.zip
http: add missing stream-like properties to OutgoingMessage
PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r--lib/_http_outgoing.js20
-rw-r--r--test/parallel/test-http-outgoing-properties.js53
2 files changed, 72 insertions, 1 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index e10f068f32..9477a9b7f7 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.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();
diff --git a/test/parallel/test-http-outgoing-properties.js b/test/parallel/test-http-outgoing-properties.js
new file mode 100644
index 0000000000..3bb6c637bf
--- /dev/null
+++ b/test/parallel/test-http-outgoing-properties.js
@@ -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);
+}