Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(net-request): transferSize now shared via 'X-TotalFetchedSize' #6050

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions lighthouse-core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,18 @@ module.exports = class NetworkRequest {
}

/**
* LR loses transfer size information and passes it in the 'X-Original-Content-Length' header.
* LR loses transfer size information, but passes it in the 'X-TotalFetchedSize' header.
*/
_updateTransferSizeForLightRiderIfNecessary() {
// Bail if we're not in LightRider, this only applies there.
if (!global.isLightRider) return;
// Bail if we somehow already have transfer size data.
if (this.transferSize) return;
// Bail if we didn't get any response headers.
if (!this.responseHeadersText) return;

const originalContentLength = this.responseHeaders.
find(item => item.name === 'X-Original-Content-Length');
// Bail if the x-original-content-length header was missing.
if (!originalContentLength) return;

// Transfer size is the original content length + length of headers
const contentBytes = parseFloat(originalContentLength.value);
const headerBytes = this.responseHeadersText.length;
this.transferSize = contentBytes + headerBytes;

const totalFetchedSize = this.responseHeaders.find(item => item.name === 'X-TotalFetchedSize');
// Bail if the header was missing.
if (!totalFetchedSize) return;
this.transferSize = parseFloat(totalFetchedSize.value);
}

/**
Expand Down