Skip to content

Commit d8aeafb

Browse files
rexagodcodebytere
authored andcommitted
http2: add writable* properties to compat api
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>
1 parent 0ef6e04 commit d8aeafb

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎lib/internal/http2/compat.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ class Http2ServerResponse extends Stream {
519519
returnthis[kStream].writableCorked;
520520
}
521521

522+
getwritableHighWaterMark(){
523+
returnthis[kStream].writableHighWaterMark;
524+
}
525+
526+
getwritableFinished(){
527+
returnthis[kStream].writableFinished;
528+
}
529+
530+
getwritableLength(){
531+
returnthis[kStream].writableLength;
532+
}
533+
522534
setstatusCode(code){
523535
code|=0;
524536
if(code>=100&&code<200)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
if(!common.hasCrypto){common.skip('missing crypto');}
4+
constassert=require('assert');
5+
consthttp2=require('http2');
6+
7+
constserver=http2.createServer(common.mustCall((req,res)=>{
8+
consthwm=req.socket.writableHighWaterMark;
9+
assert.strictEqual(res.writableHighWaterMark,hwm);
10+
assert.strictEqual(res.writableLength,0);
11+
res.write('');
12+
constlen=res.writableLength;
13+
res.write('asd');
14+
assert.strictEqual(res.writableLength,len+3);
15+
res.end();
16+
res.on('finish',common.mustCall(()=>{
17+
assert.strictEqual(res.writableLength,0);
18+
assert.ok(res.writableFinished,'writableFinished is not truthy');
19+
server.close();
20+
}));
21+
}));
22+
23+
server.listen(0,common.mustCall(()=>{
24+
constclient=http2.connect(`http://localhost:${server.address().port}`);
25+
constrequest=client.request();
26+
request.on('data',common.mustCall());
27+
request.on('end',common.mustCall(()=>{
28+
client.close();
29+
}));
30+
}));

0 commit comments

Comments
 (0)