1'use strict'; 2// Flags: --expose-internals 3 4const common = require('../common'); 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7 8const assert = require('assert'); 9const http = require('http'); 10const http2 = require('http2'); 11const { NghttpError } = require('internal/http2/util'); 12 13// Creating an http1 server here... 14// NOTE: PRI method is supported by our HTTP parser - thus the response handling 15// function must be called once before error. 16const server = http.createServer(common.mustCall((req, res) => { 17 assert.strictEqual(req.method, 'PRI'); 18 res.end(); 19})); 20 21server.listen(0, common.mustCall(() => { 22 const client = http2.connect(`http://localhost:${server.address().port}`); 23 24 const req = client.request(); 25 req.on('close', common.mustCall()); 26 27 req.on('error', common.expectsError({ 28 code: 'ERR_HTTP2_ERROR', 29 constructor: NghttpError, 30 message: 'Protocol error' 31 })); 32 33 client.on('error', common.expectsError({ 34 code: 'ERR_HTTP2_ERROR', 35 constructor: NghttpError, 36 name: 'Error', 37 message: 'Protocol error' 38 })); 39 40 client.on('close', common.mustCall(() => server.close())); 41})); 42