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 9const server = http2.createServer(); 10 11function expectsError(code) { 12 return common.expectsError({ 13 code: 'ERR_HTTP2_STATUS_INVALID', 14 name: 'RangeError', 15 message: `Invalid status code: ${code}` 16 }); 17} 18 19server.on('stream', common.mustCall((stream) => { 20 21 // Anything lower than 100 and greater than 599 is rejected 22 [ 99, 700, 1000 ].forEach((i) => { 23 assert.throws(() => stream.respond({ ':status': i }), expectsError(i)); 24 }); 25 26 stream.respond(); 27 stream.end(); 28})); 29 30server.listen(0, common.mustCall(() => { 31 const client = http2.connect(`http://localhost:${server.address().port}`); 32 const req = client.request(); 33 req.on('response', common.mustCall((headers) => { 34 assert.strictEqual(headers[':status'], 200); 35 })); 36 req.resume(); 37 req.on('end', common.mustCall(() => { 38 server.close(); 39 client.close(); 40 })); 41})); 42