Skip to content

Commit

Permalink
http: adding doc and debug for calling empty string on write function
Browse files Browse the repository at this point in the history
PR-URL: #22118
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
antsmartian authored and targos committed Sep 3, 2018
1 parent 53fb7af commit c07a065
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,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
Expand Down
5 changes: 4 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c07a065

Please sign in to comment.