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 770d6b8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 770d6b8

Please sign in to comment.