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