From 5b968b6431b182b52a6abdf9011a6409ec56203c Mon Sep 17 00:00:00 2001 From: Parth Verma Date: Mon, 24 Jun 2024 14:33:11 -0700 Subject: [PATCH] Added variable to track the downloaded content size in response --- lib/collection/response.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/collection/response.js b/lib/collection/response.js index 9b9787e7d..129b7a71d 100644 --- a/lib/collection/response.js +++ b/lib/collection/response.js @@ -255,7 +255,12 @@ _.assign(Response.prototype, /** @lends Response.prototype */ { * @private * @type {Number} */ - responseSize: stream && stream.byteLength + responseSize: stream && stream.byteLength, + + /** + * @type {Number} + */ + downloadedBytes: options.downloadedBytes }); } }); @@ -406,7 +411,8 @@ _.assign(Response.prototype, /** @lends Response.prototype */ { var sizeInfo = { body: 0, header: 0, - total: 0 + total: 0, + downloadedBytes: this.downloadedBytes }, contentEncoding = this.headers.get(CONTENT_ENCODING), @@ -441,6 +447,10 @@ _.assign(Response.prototype, /** @lends Response.prototype */ { this.body.toString().length; } + if(!sizeInfo.downloadedBytes) { + sizeInfo.downloadedBytes = sizeInfo.body; + } + // size of header is added // https://tools.ietf.org/html/rfc7230#section-3 // HTTP-message = start-line (request-line / status-line) @@ -452,7 +462,7 @@ _.assign(Response.prototype, /** @lends Response.prototype */ { this.headers.contentSize(); // compute the approximate total body size by adding size of header and body - sizeInfo.total = (sizeInfo.body || 0) + (sizeInfo.header); + sizeInfo.total = (sizeInfo.downloadedBytes || sizeInfo.body || 0) + (sizeInfo.header); return sizeInfo; },