• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11server.on('stream', common.mustCall((stream) => {
12  stream.additionalHeaders({ ':status': 102 });
13  assert.strictEqual(stream.sentInfoHeaders[0][':status'], 102);
14
15  stream.respond({ abc: 'xyz' }, { waitForTrailers: true });
16  stream.on('wantTrailers', () => {
17    stream.sendTrailers({ xyz: 'abc' });
18  });
19  assert.strictEqual(stream.sentHeaders.abc, 'xyz');
20  assert.strictEqual(stream.sentHeaders[':status'], 200);
21  assert.notStrictEqual(stream.sentHeaders.date, undefined);
22  stream.end();
23  stream.on('close', () => {
24    assert.strictEqual(stream.sentTrailers.xyz, 'abc');
25  });
26}));
27
28server.listen(0, common.mustCall(() => {
29  const client = h2.connect(`http://localhost:${server.address().port}`);
30  const req = client.request();
31
32  req.on('headers', common.mustCall((headers) => {
33    assert.strictEqual(headers[':status'], 102);
34  }));
35
36  assert.strictEqual(req.sentHeaders[':method'], 'GET');
37  assert.strictEqual(req.sentHeaders[':authority'],
38                     `localhost:${server.address().port}`);
39  assert.strictEqual(req.sentHeaders[':scheme'], 'http');
40  assert.strictEqual(req.sentHeaders[':path'], '/');
41  req.resume();
42  req.on('close', () => {
43    server.close();
44    client.close();
45  });
46}));
47