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 11const methods = [undefined, 'GET', 'POST', 'PATCH', 'FOO', 'A B C']; 12let expected = methods.length; 13 14// We use the lower-level API here 15server.on('stream', common.mustCall(onStream, expected)); 16 17function onStream(stream, headers, flags) { 18 const method = headers[':method']; 19 assert.notStrictEqual(method, undefined); 20 assert(methods.includes(method), `method ${method} not included`); 21 stream.respond({ 22 'content-type': 'text/html', 23 ':status': 200 24 }); 25 stream.end('hello world'); 26} 27 28server.listen(0); 29 30server.on('listening', common.mustCall(() => { 31 32 const client = h2.connect(`http://localhost:${server.address().port}`); 33 34 const headers = { ':path': '/' }; 35 36 methods.forEach((method) => { 37 headers[':method'] = method; 38 const req = client.request(headers); 39 req.on('response', common.mustCall()); 40 req.resume(); 41 req.on('end', common.mustCall(() => { 42 if (--expected === 0) { 43 server.close(); 44 client.close(); 45 } 46 })); 47 req.end(); 48 }); 49})); 50