From d39db532a2ca9ebd7754dd364f88cf8bf0ed0a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20G=C3=A4bler?= <14858479+florian-g2@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:41:02 +0200 Subject: [PATCH] docs(response-stream): add comments and references explaining implementation --- src/network/response-stream.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/network/response-stream.ts b/src/network/response-stream.ts index d82266cc..22a264ef 100644 --- a/src/network/response-stream.ts +++ b/src/network/response-stream.ts @@ -113,12 +113,18 @@ export class ServerlessStreamResponse extends ServerResponse { return true; } + // node sends the last chunk crlf as a string: + // https://github.com/nodejs/node/blob/v22.8.0/lib/_http_outgoing.js#L1131 if (data === endChunked) { internalWritable.end(cb); return true; } - // if header or data crlf + // check for header or data crlf + // node sends the header and data crlf as a buffer + // below code is aligned to following node implementation of the HTTP/1.1 chunked transfer coding: + // https://github.com/nodejs/node/blob/v22.8.0/lib/_http_outgoing.js#L1012-L1015 + // for reference: https://datatracker.ietf.org/doc/html/rfc9112#section-7 if (Buffer.isBuffer(data) && crlfBuffer.equals(data)) { const isHeaderCrlf = !firstCrlfBufferEncountered; if (isHeaderCrlf) {