From 770d6b8f3d798a1058e43b1d842771fb019712d4 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 17 Feb 2023 10:39:49 +0100 Subject: [PATCH] fixup: cleanup --- lib/_http_outgoing.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 7ac93bd3d8f498..f097bd4c8413e4 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -876,16 +876,15 @@ function write_(msg, chunk, encoding, callback, fromEnd) { return false; } - let len = msg.strictContentLength ? - typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength : null; + let len; - if (len != null) { - if ( - strictContentLength(msg) && - (fromEnd ? msg[kBytesWritten] + len !== msg._contentLength : msg[kBytesWritten] + len > msg._contentLength) - ) { + if (strictContentLength(msg)) { + len ??= typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength; + + if (fromEnd ? msg[kBytesWritten] + len !== msg._contentLength : msg[kBytesWritten] + len > msg._contentLength) { throw new ERR_HTTP_CONTENT_LENGTH_MISMATCH(len + msg[kBytesWritten], msg._contentLength); } + msg[kBytesWritten] += len; }