1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const h2 = require('http2'); 8 9const server = h2.createServer(); 10 11server.on('stream', common.mustCall((stream) => { 12 assert(stream.session); 13 stream.session.destroy(); 14 assert.strictEqual(stream.session, undefined); 15 16 // Test that stream.state getter returns an empty object 17 // when the stream session has been destroyed 18 assert.deepStrictEqual({}, stream.state); 19 20 // Test that ERR_HTTP2_INVALID_STREAM is thrown while calling 21 // stream operations after the stream session has been destroyed 22 const invalidStreamError = { 23 name: 'Error', 24 code: 'ERR_HTTP2_INVALID_STREAM', 25 message: 'The stream has been destroyed' 26 }; 27 assert.throws(() => stream.additionalHeaders(), invalidStreamError); 28 assert.throws(() => stream.priority(), invalidStreamError); 29 assert.throws(() => stream.respond(), invalidStreamError); 30 assert.throws( 31 () => stream.pushStream({}, common.mustNotCall()), 32 { 33 code: 'ERR_HTTP2_PUSH_DISABLED', 34 name: 'Error' 35 } 36 ); 37 stream.on('error', common.expectsError({ 38 name: 'Error', 39 code: 'ERR_STREAM_WRITE_AFTER_END', 40 message: 'write after end' 41 })); 42 assert.strictEqual(stream.write('data', common.expectsError({ 43 name: 'Error', 44 code: 'ERR_STREAM_WRITE_AFTER_END', 45 message: 'write after end' 46 })), false); 47})); 48 49server.listen(0, common.mustCall(() => { 50 const client = h2.connect(`http://localhost:${server.address().port}`); 51 const req = client.request(); 52 req.resume(); 53 req.on('end', common.mustCall()); 54 req.on('close', common.mustCall(() => server.close(common.mustCall()))); 55})); 56