• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5const assert = require('assert');
6const http2 = require('http2');
7const makeDuplexPair = require('../common/duplexpair');
8
9{
10  const testData = '<h1>Hello World</h1>';
11  const server = http2.createServer();
12  server.on('stream', common.mustCall((stream, headers) => {
13    stream.respond({
14      'content-type': 'text/html',
15      ':status': 200
16    });
17    stream.end(testData);
18  }));
19
20  const { clientSide, serverSide } = makeDuplexPair();
21  server.emit('connection', serverSide);
22
23  const client = http2.connect('http://localhost:80', {
24    createConnection: common.mustCall(() => clientSide)
25  });
26
27  const req = client.request({ ':path': '/' });
28
29  req.on('response', common.mustCall((headers) => {
30    assert.strictEqual(headers[':status'], 200);
31  }));
32
33  req.setEncoding('utf8');
34  // Note: This is checking that this small amount of data is passed through in
35  // a single chunk, which is unusual for our test suite but seems like a
36  // reasonable assumption here.
37  req.on('data', common.mustCall((data) => {
38    assert.strictEqual(data, testData);
39  }));
40  req.on('end', common.mustCall(() => {
41    clientSide.destroy();
42    clientSide.end();
43  }));
44  req.end();
45}
46