@@ -17,7 +17,7 @@ const isGreaterThanv20 = gte(process.version.slice(1), '20.0.0')
17
17
// https://github.com/nodejs/node/pull/41735
18
18
const hasPseudoHeadersOrderFix = gte ( process . version . slice ( 1 ) , '16.14.1' )
19
19
20
- plan ( 21 )
20
+ plan ( 22 )
21
21
22
22
test ( 'Should support H2 connection' , async t => {
23
23
const body = [ ]
@@ -67,6 +67,64 @@ test('Should support H2 connection', async t => {
67
67
t . equal ( Buffer . concat ( body ) . toString ( 'utf8' ) , 'hello h2!' )
68
68
} )
69
69
70
+ test ( 'Should support H2 connection(multiple requests)' , async t => {
71
+ const server = createSecureServer ( pem )
72
+
73
+ server . on ( 'stream' , async ( stream , headers , _flags , rawHeaders ) => {
74
+ t . equal ( headers [ 'x-my-header' ] , 'foo' )
75
+ t . equal ( headers [ ':method' ] , 'POST' )
76
+ const reqData = [ ]
77
+ stream . on ( 'data' , chunk => reqData . push ( chunk . toString ( ) ) )
78
+ await once ( stream , 'end' )
79
+ const reqBody = reqData . join ( '' )
80
+ t . equal ( reqBody . length > 0 , true )
81
+ stream . respond ( {
82
+ 'content-type' : 'text/plain; charset=utf-8' ,
83
+ 'x-custom-h2' : 'hello' ,
84
+ ':status' : 200
85
+ } )
86
+ stream . end ( `hello h2! ${ reqBody } ` )
87
+ } )
88
+
89
+ server . listen ( 0 )
90
+ await once ( server , 'listening' )
91
+
92
+ const client = new Client ( `https://localhost:${ server . address ( ) . port } ` , {
93
+ connect : {
94
+ rejectUnauthorized : false
95
+ } ,
96
+ allowH2 : true
97
+ } )
98
+
99
+ t . plan ( 21 )
100
+ t . teardown ( server . close . bind ( server ) )
101
+ t . teardown ( client . close . bind ( client ) )
102
+
103
+ for ( let i = 0 ; i < 3 ; i ++ ) {
104
+ const sendBody = `seq ${ i } `
105
+ const body = [ ]
106
+ const response = await client . request ( {
107
+ path : '/' ,
108
+ method : 'POST' ,
109
+ headers : {
110
+ 'content-type' : 'text/plain; charset=utf-8' ,
111
+ 'x-my-header' : 'foo'
112
+ } ,
113
+ body : Readable . from ( sendBody )
114
+ } )
115
+
116
+ response . body . on ( 'data' , chunk => {
117
+ body . push ( chunk )
118
+ } )
119
+
120
+ await once ( response . body , 'end' )
121
+ t . equal ( response . statusCode , 200 )
122
+ t . equal ( response . headers [ 'content-type' ] , 'text/plain; charset=utf-8' )
123
+ t . equal ( response . headers [ 'x-custom-h2' ] , 'hello' )
124
+ t . equal ( Buffer . concat ( body ) . toString ( 'utf8' ) , `hello h2! ${ sendBody } ` )
125
+ }
126
+ } )
127
+
70
128
test ( 'Should support H2 connection (headers as array)' , async t => {
71
129
const body = [ ]
72
130
const server = createSecureServer ( pem )
0 commit comments