• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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...
14const server = http.createServer(common.mustNotCall())
15  .on('clientError', common.mustCall((error, socket) => {
16    assert.strictEqual(error.code, 'HPE_PAUSED_H2_UPGRADE');
17    assert.strictEqual(error.bytesParsed, 24);
18    socket.write('HTTP/1.1 400 No H2 support\r\n\r\n');
19
20    // Don't give client a chance to send a preamble.
21    socket.destroy();
22  }));
23
24server.listen(0, common.mustCall(() => {
25  const client = http2.connect(`http://localhost:${server.address().port}`);
26
27  const req = client.request();
28  req.on('close', common.mustCall());
29
30  req.on('error', common.expectsError({
31    code: 'ERR_HTTP2_ERROR',
32    constructor: NghttpError,
33    message: 'Protocol error'
34  }));
35
36  client.on('error', common.expectsError({
37    code: 'ERR_HTTP2_ERROR',
38    constructor: NghttpError,
39    name: 'Error',
40    message: 'Protocol error'
41  }));
42
43  client.on('close', common.mustCall(() => server.close()));
44}));
45