@@ -11,18 +11,30 @@ const h2 = require('http2');
11
11
const net = require ( 'net' ) ;
12
12
const { NghttpError } = require ( 'internal/http2/util' ) ;
13
13
const h2test = require ( '../common/http2' ) ;
14
+ let client ;
14
15
15
16
const server = h2 . createServer ( ) ;
16
17
server . on ( 'stream' , common . mustCall ( ( stream ) => {
17
18
stream . respond ( ) ;
18
- stream . end ( 'ok' ) ;
19
19
20
- stream . on ( 'error' , common . expectsError ( {
21
- code : 'ERR_HTTP2_ERROR' ,
22
- constructor : NghttpError ,
23
- message : 'Stream was already closed or invalid'
24
- } ) ) ;
25
- stream . on ( 'close' , common . mustCall ( ) ) ;
20
+ if ( stream . id === 3 ) {
21
+ stream . on ( 'close' , ( ) => {
22
+ // A second Stream ID 1 frame should fail.
23
+ // This will cause an error to occur because the client is
24
+ // attempting to reuse an already closed stream. This must
25
+ // cause the server session to be torn down.
26
+ client . write ( id1 . data ) ;
27
+ // This Stream ID 5 frame will never make it to the server.
28
+ client . write ( id5 . data ) ;
29
+ } ) ;
30
+ stream . end ( 'ok' ) ;
31
+ } else {
32
+ stream . on ( 'error' , common . expectsError ( {
33
+ code : 'ERR_HTTP2_ERROR' ,
34
+ constructor : NghttpError ,
35
+ message : 'Stream was already closed or invalid'
36
+ } ) ) ;
37
+ }
26
38
27
39
// Stream ID 5 should never reach the server
28
40
assert . notStrictEqual ( stream . id , 5 ) ;
@@ -45,23 +57,14 @@ const id3 = new h2test.HeadersFrame(3, h2test.kFakeRequestHeaders, 0, true);
45
57
const id5 = new h2test . HeadersFrame ( 5 , h2test . kFakeRequestHeaders , 0 , true ) ;
46
58
47
59
server . listen ( 0 , ( ) => {
48
- const client = net . connect ( server . address ( ) . port , ( ) => {
60
+ client = net . connect ( server . address ( ) . port , ( ) => {
49
61
client . write ( h2test . kClientMagic , ( ) => {
50
62
client . write ( settings . data , ( ) => {
51
63
client . write ( settingsAck . data ) ;
52
64
// Stream ID 1 frame will make it OK.
53
65
client . write ( id1 . data , ( ) => {
54
66
// Stream ID 3 frame will make it OK.
55
- client . write ( id3 . data , ( ) => {
56
- // A second Stream ID 1 frame should fail.
57
- // This will cause an error to occur because the client is
58
- // attempting to reuse an already closed stream. This must
59
- // cause the server session to be torn down.
60
- client . write ( id1 . data , ( ) => {
61
- // This Stream ID 5 frame will never make it to the server
62
- client . write ( id5 . data ) ;
63
- } ) ;
64
- } ) ;
67
+ client . write ( id3 . data ) ;
65
68
} ) ;
66
69
} ) ;
67
70
} ) ;
0 commit comments