Skip to content

Commit

Permalink
Added variable to track the downloaded content size in response
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jun 24, 2024
1 parent e1dfe7a commit 5b968b6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/collection/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
});
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -441,6 +447,10 @@ _.assign(Response.prototype, /** @lends Response.prototype */ {
this.body.toString().length;
}

if(!sizeInfo.downloadedBytes) {

Check failure on line 450 in lib/collection/response.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space(s) after "if"
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)
Expand All @@ -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;
},
Expand Down

0 comments on commit 5b968b6

Please sign in to comment.