-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: always call response.write() callback
Ensure that the callback of `OutgoingMessage.prototype.write()` is called even when writing empty chunks. Fixes: #22066 PR-URL: #27709 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
4 changed files
with
57 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/parallel/test-http-outgoing-message-write-callback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
// This test ensures that the callback of `OutgoingMessage.prototype.write()` is | ||
// called also when writing empty chunks. | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
const stream = require('stream'); | ||
|
||
const expected = ['a', 'b', '', Buffer.alloc(0), 'c']; | ||
const results = []; | ||
|
||
const writable = new stream.Writable({ | ||
write(chunk, encoding, callback) { | ||
setImmediate(callback); | ||
} | ||
}); | ||
|
||
const res = new http.ServerResponse({ | ||
method: 'GET', | ||
httpVersionMajor: 1, | ||
httpVersionMinor: 1 | ||
}); | ||
|
||
res.assignSocket(writable); | ||
|
||
for (const chunk of expected) { | ||
res.write(chunk, () => { | ||
results.push(chunk); | ||
}); | ||
} | ||
|
||
res.end(common.mustCall(() => { | ||
assert.deepStrictEqual(results, expected); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters