Skip to content

Commit 499171b

Browse files
ofirbarakruyadorno
authored andcommitted
http2: fix no response event on continue request
When sending a continue request, server response with null, it does not fires the response event type Fixes: #38258 PR-URL: #41739 Refs: #38561 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bee4451 commit 499171b

File tree

2 files changed

+75
-35
lines changed

2 files changed

+75
-35
lines changed

‎lib/internal/http2/core.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders){
394394
}
395395
}elseif(cat===NGHTTP2_HCAT_PUSH_RESPONSE){
396396
event='push';
397-
// cat === NGHTTP2_HCAT_HEADERS:
398-
}elseif(!endOfStream&&status!==undefined&&status>=200){
397+
}elseif(status!==undefined&&status>=200){
399398
event='response';
400399
}else{
401400
event=endOfStream ? 'trailers' : 'headers';

‎test/parallel/test-http2-compat-expect-continue.js‎

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,90 @@ if (!common.hasCrypto)
66
constassert=require('assert');
77
consthttp2=require('http2');
88

9-
consttestResBody='other stuff!\n';
9+
{
10+
consttestResBody='other stuff!\n';
1011

11-
// Checks the full 100-continue flow from client sending 'expect: 100-continue'
12-
// through server receiving it, sending back :status 100, writing the rest of
13-
// the request to finally the client receiving to.
12+
// Checks the full 100-continue flow from client sending 'expect: 100-continue'
13+
// through server receiving it, sending back :status 100, writing the rest of
14+
// the request to finally the client receiving to.
1415

15-
constserver=http2.createServer();
16+
constserver=http2.createServer();
1617

17-
letsentResponse=false;
18+
letsentResponse=false;
1819

19-
server.on('request',common.mustCall((req,res)=>{
20-
res.end(testResBody);
21-
sentResponse=true;
22-
}));
20+
server.on('request',common.mustCall((req,res)=>{
21+
res.end(testResBody);
22+
sentResponse=true;
23+
}));
24+
25+
server.listen(0);
26+
27+
server.on('listening',common.mustCall(()=>{
28+
letbody='';
2329

24-
server.listen(0);
30+
constclient=http2.connect(`http://localhost:${server.address().port}`);
31+
constreq=client.request({
32+
':method': 'POST',
33+
'expect': '100-continue'
34+
});
2535

26-
server.on('listening',common.mustCall(()=>{
27-
letbody='';
36+
letgotContinue=false;
37+
req.on('continue',common.mustCall(()=>{
38+
gotContinue=true;
39+
}));
2840

29-
constclient=http2.connect(`http://localhost:${server.address().port}`);
30-
constreq=client.request({
31-
':method': 'POST',
32-
'expect': '100-continue'
33-
});
41+
req.on('response',common.mustCall((headers)=>{
42+
assert.strictEqual(gotContinue,true);
43+
assert.strictEqual(sentResponse,true);
44+
assert.strictEqual(headers[':status'],200);
45+
req.end();
46+
}));
3447

35-
letgotContinue=false;
36-
req.on('continue',common.mustCall(()=>{
37-
gotContinue=true;
48+
req.setEncoding('utf8');
49+
req.on('data',common.mustCall((chunk)=>{body+=chunk;}));
50+
req.on('end',common.mustCall(()=>{
51+
assert.strictEqual(body,testResBody);
52+
client.close();
53+
server.close();
54+
}));
3855
}));
56+
}
57+
58+
{
59+
// Checks the full 100-continue flow from client sending 'expect: 100-continue'
60+
// through server receiving it and ending the request.
61+
62+
constserver=http2.createServer();
3963

40-
req.on('response',common.mustCall((headers)=>{
41-
assert.strictEqual(gotContinue,true);
42-
assert.strictEqual(sentResponse,true);
43-
assert.strictEqual(headers[':status'],200);
44-
req.end();
64+
server.on('request',common.mustCall((req,res)=>{
65+
res.end();
4566
}));
4667

47-
req.setEncoding('utf8');
48-
req.on('data',common.mustCall((chunk)=>{body+=chunk;}));
49-
req.on('end',common.mustCall(()=>{
50-
assert.strictEqual(body,testResBody);
51-
client.close();
52-
server.close();
68+
server.listen(0);
69+
70+
server.on('listening',common.mustCall(()=>{
71+
constclient=http2.connect(`http://localhost:${server.address().port}`);
72+
constreq=client.request({
73+
':path': '/',
74+
'expect': '100-continue'
75+
});
76+
77+
letgotContinue=false;
78+
req.on('continue',common.mustCall(()=>{
79+
gotContinue=true;
80+
}));
81+
82+
letgotResponse=false;
83+
req.on('response',common.mustCall(()=>{
84+
gotResponse=true;
85+
}));
86+
87+
req.setEncoding('utf8');
88+
req.on('end',common.mustCall(()=>{
89+
assert.strictEqual(gotContinue,true);
90+
assert.strictEqual(gotResponse,true);
91+
client.close();
92+
server.close();
93+
}));
5394
}));
54-
}));
95+
}

0 commit comments

Comments
(0)