http: adding doc and debug for calling empty string on write function

PR-URL: https://github.com/nodejs/node/pull/22118
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
pull/22355/merge
Anto Aravinth 2018-08-21 19:50:04 +05:30 committed by Matteo Collina
parent 98cf84f2c9
commit 413a7e1dea
2 changed files with 7 additions and 1 deletions

View File

@ -750,6 +750,9 @@ Returns `true` if the entire data was flushed successfully to the kernel
buffer. Returns `false` if all or part of the data was queued in user memory.
`'drain'` will be emitted when the buffer is free again.
When `write` function is called with empty string or buffer, it does
nothing and waits for more input.
## Class: http.Server
<!-- YAML
added: v0.1.17

View File

@ -599,7 +599,10 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
// If we get an empty string or buffer, then just do nothing, and
// signal the user to keep writing.
if (chunk.length === 0) return true;
if (chunk.length === 0) {
debug('received empty string or buffer and waiting for more input');
return true;
}
if (!fromEnd && msg.connection && !msg[kIsCorked]) {
msg.connection.cork();