Skip to content

Commit

Permalink
fixup: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 17, 2023
1 parent e259ee6 commit 20c7f2f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,16 +876,18 @@ 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 (msg.strictContentLength) {
len ??= typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.byteLength;

if (len != null) {
if (
strictContentLength(msg) &&
(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;
}

Expand Down

0 comments on commit 20c7f2f

Please sign in to comment.