• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4
5// This test ensures that the callback of `OutgoingMessage.prototype.write()` is
6// called also when writing empty chunks or when the message has no body.
7
8const assert = require('assert');
9const http = require('http');
10const stream = require('stream');
11
12for (const method of ['GET, HEAD']) {
13  const expected = ['a', 'b', '', Buffer.alloc(0), 'c'];
14  const results = [];
15
16  const writable = new stream.Writable({
17    write(chunk, encoding, callback) {
18      callback();
19    }
20  });
21
22  const res = new http.ServerResponse({
23    method: method,
24    httpVersionMajor: 1,
25    httpVersionMinor: 1
26  });
27
28  res.assignSocket(writable);
29
30  for (const chunk of expected) {
31    res.write(chunk, () => {
32      results.push(chunk);
33    });
34  }
35
36  res.end(common.mustCall(() => {
37    assert.deepStrictEqual(results, expected);
38  }));
39}
40