diff --git a/doc/api/stream.md b/doc/api/stream.md index 0297af92600654..3d701b1b0b625f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1528,7 +1528,7 @@ function parseHeader(stream, callback) { let chunk; while (null !== (chunk = stream.read())) { const str = decoder.write(chunk); - if (str.match(/\n\n/)) { + if (str.includes('\n\n')) { // Found the header boundary. const split = str.split(/\n\n/); header += split.shift(); @@ -1541,10 +1541,10 @@ function parseHeader(stream, callback) { stream.unshift(buf); // Now the body of the message can be read from the stream. callback(null, header, stream); - } else { - // Still reading the header. - header += str; + return; } + // Still reading the header. + header += str; } } }