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 [ 13 ':path', 14 ':authority', 15 ':method', 16 ':scheme', 17 ].forEach((i) => { 18 assert.throws(() => stream.respond({ [i]: '/' }), 19 { 20 code: 'ERR_HTTP2_INVALID_PSEUDOHEADER' 21 }); 22 }); 23 24 stream.respond({}, { waitForTrailers: true }); 25 26 stream.on('wantTrailers', () => { 27 assert.throws(() => { 28 stream.sendTrailers({ ':status': 'bar' }); 29 }, { 30 code: 'ERR_HTTP2_INVALID_PSEUDOHEADER' 31 }); 32 stream.close(); 33 }); 34 35 stream.end('hello world'); 36})); 37 38 39server.listen(0, common.mustCall(() => { 40 const client = h2.connect(`http://localhost:${server.address().port}`); 41 const req = client.request(); 42 43 req.on('response', common.mustCall()); 44 req.resume(); 45 req.on('end', common.mustCall()); 46 req.on('close', common.mustCall(() => { 47 server.close(); 48 client.close(); 49 })); 50})); 51