• 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
9// Check that drain event is passed from Http2Stream
10
11const testString = 'tests';
12
13const server = h2.createServer();
14
15server.on('request', common.mustCall((req, res) => {
16  res.stream._writableState.highWaterMark = testString.length;
17  assert.strictEqual(res.write(testString), false);
18  res.on('drain', common.mustCall(() => res.end(testString)));
19}));
20
21server.listen(0, common.mustCall(() => {
22  const port = server.address().port;
23
24  const client = h2.connect(`http://localhost:${port}`);
25  const request = client.request({
26    ':path': '/foobar',
27    ':method': 'POST',
28    ':scheme': 'http',
29    ':authority': `localhost:${port}`
30  });
31  request.resume();
32  request.end();
33
34  let data = '';
35  request.setEncoding('utf8');
36  request.on('data', (chunk) => (data += chunk));
37
38  request.on('end', common.mustCall(function() {
39    assert.strictEqual(data, testString.repeat(2));
40    client.close();
41    server.close();
42  }));
43}));
44