1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8 9// Check that pushStream handles being passed wrong arguments 10// in the expected manner 11 12const server = http2.createServer(); 13server.on('stream', common.mustCall((stream, headers) => { 14 const port = server.address().port; 15 16 // Must receive a callback (function) 17 assert.throws( 18 () => stream.pushStream({ 19 ':scheme': 'http', 20 ':path': '/foobar', 21 ':authority': `localhost:${port}`, 22 }, {}, 'callback'), 23 { 24 code: 'ERR_INVALID_ARG_TYPE', 25 } 26 ); 27 28 // Must validate headers 29 assert.throws( 30 () => stream.pushStream({ 'connection': 'test' }, {}, () => {}), 31 { 32 code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', 33 name: 'TypeError', 34 message: 'HTTP/1 Connection specific headers are forbidden: "connection"' 35 } 36 ); 37 38 stream.end('test'); 39})); 40 41server.listen(0, common.mustCall(() => { 42 const port = server.address().port; 43 const headers = { ':path': '/' }; 44 const client = http2.connect(`http://localhost:${port}`); 45 const req = client.request(headers); 46 req.setEncoding('utf8'); 47 48 let data = ''; 49 req.on('data', common.mustCall((d) => data += d)); 50 req.on('end', common.mustCall(() => { 51 assert.strictEqual(data, 'test'); 52 server.close(); 53 client.close(); 54 })); 55 req.end(); 56})); 57