From 4e847d9aba8ae9e015d5404e4e95b0420a7aa1f8 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Fri, 22 May 2020 05:48:40 +0530 Subject: [PATCH 1/3] http2: [compat api] add writable* properties added writableHighWaterMark, writableLength, and writableFinished properties with test. Refs: https://github.com/nodejs/node/issues/29829 --- lib/internal/http2/compat.js | 12 ++++++++ .../test-http2-outgoing-properties.js | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/parallel/test-http2-outgoing-properties.js diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 851fec4b3a6ae5..c49f3b26166b58 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -519,6 +519,18 @@ class Http2ServerResponse extends Stream { return this[kStream].writableCorked; } + get writableHighWaterMark() { + return this[kStream].writableHighWaterMark; + } + + get writableFinished() { + return this[kStream].writableFinished; + } + + get writableLength() { + return this[kStream].writableLength; + } + set statusCode(code) { code |= 0; if (code >= 100 && code < 200) diff --git a/test/parallel/test-http2-outgoing-properties.js b/test/parallel/test-http2-outgoing-properties.js new file mode 100644 index 00000000000000..cbb1b2c89dc315 --- /dev/null +++ b/test/parallel/test-http2-outgoing-properties.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) { common.skip('missing crypto'); } +const assert = require('assert'); +const http2 = require('http2'); + +const server = http2.createServer(common.mustCall((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 + 3); + res.end(); + res.on('finish', common.mustCall(() => { + assert.strictEqual(res.writableLength, 0); + assert.ok(res.writableFinished, 'writableFinished is not truthy'); + server.close(); + })); +})); + +server.listen(0, common.mustCall(() => { + const client = http2.connect(`http://localhost:${server.address().port}`); + const request = client.request(); + request.on('data', common.mustCall((d) => { })); + request.on('end', common.mustCall(() => { + client.close(); + })); +})); From a103c6a3f90c68abd883382a819641ca0b1b3f31 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Fri, 22 May 2020 15:11:34 +0530 Subject: [PATCH 2/3] nit: rename test --- ...tgoing-properties.js => test-http2-res-writable-properties.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/parallel/{test-http2-outgoing-properties.js => test-http2-res-writable-properties.js} (100%) diff --git a/test/parallel/test-http2-outgoing-properties.js b/test/parallel/test-http2-res-writable-properties.js similarity index 100% rename from test/parallel/test-http2-outgoing-properties.js rename to test/parallel/test-http2-res-writable-properties.js From a729aa150e5f00d46478a5126dcdddb23ecbec09 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Mon, 25 May 2020 01:00:53 +0530 Subject: [PATCH 3/3] Update test/parallel/test-http2-res-writable-properties.js Co-authored-by: Luigi Pinca --- test/parallel/test-http2-res-writable-properties.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-http2-res-writable-properties.js b/test/parallel/test-http2-res-writable-properties.js index cbb1b2c89dc315..488cb1babf3e8a 100644 --- a/test/parallel/test-http2-res-writable-properties.js +++ b/test/parallel/test-http2-res-writable-properties.js @@ -23,7 +23,7 @@ const server = http2.createServer(common.mustCall((req, res) => { server.listen(0, common.mustCall(() => { const client = http2.connect(`http://localhost:${server.address().port}`); const request = client.request(); - request.on('data', common.mustCall((d) => { })); + request.on('data', common.mustCall()); request.on('end', common.mustCall(() => { client.close(); }));