Skip to content

Commit 2de17ea

Browse files
jasnellBethGriggs
authored andcommitted
http2: add http2stream.endAfterHeaders property
Indicates is the END_STREAM flag was set on the received HEADERS frame Backport-PR-URL: #22850 PR-URL: #22843Fixes: #22497 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent bae7c60 commit 2de17ea

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎doc/api/http2.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,17 @@ added: v8.4.0
952952
Set to `true` if the `Http2Stream` instance has been destroyed and is no longer
953953
usable.
954954

955+
#### http2stream.endAfterHeaders
956+
<!-- YAML
957+
added: REPLACEME
958+
-->
959+
960+
* {boolean}
961+
962+
Set the `true` if the `END_STREAM` flag was set in the request or response
963+
HEADERS frame received, indicating that no additional data should be received
964+
and the readable side of the `Http2Stream` will be closed.
965+
955966
#### http2stream.pending
956967
<!-- YAML
957968
added: v8.11.2

‎lib/internal/http2/core.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ function onSessionHeaders(handle, id, cat, flags, headers) {
219219
}else{
220220
stream=newClientHttp2Stream(session,handle,id,opts);
221221
}
222+
if(endOfStream)
223+
stream[kState].endAfterHeaders=true;
222224
process.nextTick(emit,session,'stream',stream,obj,flags,headers);
223225
}else{
224226
letevent;
@@ -1557,7 +1559,8 @@ class Http2Stream extends Duplex {
15571559
flags: STREAM_FLAGS_PENDING,
15581560
rstCode: NGHTTP2_NO_ERROR,
15591561
writeQueueSize: 0,
1560-
trailersReady: false
1562+
trailersReady: false,
1563+
endAfterHeaders: false
15611564
};
15621565

15631566
this.on('pause',streamOnPause);
@@ -1602,6 +1605,10 @@ class Http2Stream extends Duplex {
16021605
return`Http2Stream ${util.format(obj)}`;
16031606
}
16041607

1608+
getendAfterHeaders(){
1609+
returnthis[kState].endAfterHeaders;
1610+
}
1611+
16051612
getsentHeaders(){
16061613
returnthis[kSentHeaders];
16071614
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
if(!common.hasCrypto)
5+
common.skip('missing crypto');
6+
constassert=require('assert');
7+
consthttp2=require('http2');
8+
constCountdown=require('../common/countdown');
9+
10+
constserver=http2.createServer();
11+
server.on('stream',common.mustCall((stream,headers)=>{
12+
constcheck=headers[':method']==='GET' ? true : false;
13+
assert.strictEqual(stream.endAfterHeaders,check);
14+
stream.on('data',common.mustNotCall());
15+
stream.on('end',common.mustCall());
16+
stream.respond();
17+
stream.end('ok');
18+
},2));
19+
20+
constcountdown=newCountdown(2,()=>server.close());
21+
22+
server.listen(0,common.mustCall(()=>{
23+
{
24+
constclient=http2.connect(`http://localhost:${server.address().port}`);
25+
constreq=client.request();
26+
27+
req.resume();
28+
req.on('response',common.mustCall(()=>{
29+
assert.strictEqual(req.endAfterHeaders,false);
30+
}));
31+
req.on('end',common.mustCall(()=>{
32+
client.close();
33+
countdown.dec();
34+
}));
35+
}
36+
{
37+
constclient=http2.connect(`http://localhost:${server.address().port}`);
38+
constreq=client.request({':method': 'POST'});
39+
40+
req.resume();
41+
req.end();
42+
req.on('response',common.mustCall(()=>{
43+
assert.strictEqual(req.endAfterHeaders,false);
44+
}));
45+
req.on('end',common.mustCall(()=>{
46+
client.close();
47+
countdown.dec();
48+
}));
49+
}
50+
}));

0 commit comments

Comments
 (0)