Skip to content

Commit 770d6b8

Browse files
committed
fixup: cleanup
1 parent e259ee6 commit 770d6b8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/_http_outgoing.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,16 +876,15 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
876876
return false;
877877
}
878878

879-
let len = msg.strictContentLength ?
880-
typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength : null;
879+
let len;
881880

882-
if (len != null) {
883-
if (
884-
strictContentLength(msg) &&
885-
(fromEnd ? msg[kBytesWritten] + len !== msg._contentLength : msg[kBytesWritten] + len > msg._contentLength)
886-
) {
881+
if (strictContentLength(msg)) {
882+
len ??= typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength;
883+
884+
if (fromEnd ? msg[kBytesWritten] + len !== msg._contentLength : msg[kBytesWritten] + len > msg._contentLength) {
887885
throw new ERR_HTTP_CONTENT_LENGTH_MISMATCH(len + msg[kBytesWritten], msg._contentLength);
888886
}
887+
889888
msg[kBytesWritten] += len;
890889
}
891890

0 commit comments

Comments
 (0)