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
11// We use the lower-level API here
12server.on('stream', common.mustCall(onStream));
13
14function onStream(stream, headers, flags) {
15  stream.close();
16
17  assert.throws(() => {
18    stream.additionalHeaders({
19      ':status': 123,
20      'abc': 123
21    });
22  }, { code: 'ERR_HTTP2_INVALID_STREAM' });
23}
24
25server.listen(0);
26
27server.on('listening', common.mustCall(() => {
28  const client = h2.connect(`http://localhost:${server.address().port}`);
29  const req = client.request();
30  req.on('headers', common.mustNotCall());
31  req.on('close', common.mustCall(() => {
32    assert.strictEqual(h2.constants.NGHTTP2_NO_ERROR, req.rstCode);
33    server.close();
34    client.close();
35  }));
36  req.on('response', common.mustNotCall());
37}));
38