• 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
11const setCookie = [
12  'a=b',
13  'c=d; Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly',
14  'e=f',
15];
16
17// We use the lower-level API here
18server.on('stream', common.mustCall(onStream));
19
20function onStream(stream, headers, flags) {
21
22  assert.strictEqual(typeof headers.abc, 'string');
23  assert.strictEqual(headers.abc, '1, 2, 3');
24  assert.strictEqual(typeof headers.cookie, 'string');
25  assert.strictEqual(headers.cookie, 'a=b; c=d; e=f');
26
27  stream.respond({
28    'content-type': 'text/html',
29    ':status': 200,
30    'set-cookie': setCookie
31  });
32
33  stream.end('hello world');
34}
35
36server.listen(0);
37
38server.on('listening', common.mustCall(() => {
39
40  const client = h2.connect(`http://localhost:${server.address().port}`);
41
42  const req = client.request({
43    ':path': '/',
44    'abc': [1, 2, 3],
45    'cookie': ['a=b', 'c=d', 'e=f'],
46  });
47  req.resume();
48
49  req.on('response', common.mustCall((headers) => {
50    assert(Array.isArray(headers['set-cookie']));
51    assert.deepStrictEqual(headers['set-cookie'], setCookie);
52  }));
53
54  req.on('end', common.mustCall(() => {
55    server.close();
56    client.close();
57  }));
58  req.end();
59
60}));
61