doc: fix bug in readable.unshift code example

PR-URL: https://github.com/nodejs/node/pull/41944
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Xuguang Mei 2022-02-15 19:01:36 +08:00 committed by GitHub
parent d17be0fbe5
commit ee38bbd4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1586,7 +1586,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();
@ -1599,10 +1599,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;
}
}
}