Skip to content

Commit

Permalink
http2: add writable* properties to compat api
Browse files Browse the repository at this point in the history
added writableHighWaterMark, writableLength, and writableFinished
properties with test.

Refs: #29829

PR-URL: #33506
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
rexagod authored and codebytere committed Jul 8, 2020
1 parent 8def934 commit 0f0720a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-http2-res-writable-properties.js
Original file line number Diff line number Diff line change
@@ -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());
request.on('end', common.mustCall(() => {
client.close();
}));
}));

0 comments on commit 0f0720a

Please sign in to comment.