summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-byteswritten-server.js
blob: 3077687fbf9a3bb1a52370becdff7df6c3565445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');

const http2Server = http2.createServer(common.mustCall(function(req, res) {
  res.socket.on('finish', common.mustCall(() => {
    assert(req.socket.bytesWritten > 0); // 1094
  }));
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write(Buffer.from('1'.repeat(1024)));
  res.end();
}));

http2Server.listen(0, common.mustCall(function() {
  const URL = `http://localhost:${http2Server.address().port}`;
  const http2client = http2.connect(URL, { protocol: 'http:' });
  const req = http2client.request({ ':method': 'GET', ':path': '/' });
  req.on('data', common.mustCall());
  req.on('end', common.mustCall(function() {
    http2client.close();
    http2Server.close();
  }));
  req.end();
}));