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

Include the size of 304 responses see https://github.com/sitespeedio/… #60

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
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
24 changes: 10 additions & 14 deletions lib/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,17 @@ module.exports = {
* @private
*/
contentType: (asset, contentTypes) => {
if (!/^2\d{2}/.test(asset.status)) {
return;
}

// TODO how to handle unknown?
if (/^2\d{2}/.test(asset.status) || asset.status === 304) {
const contentData = contentTypes[asset.type] || newContentData();

const contentData = contentTypes[asset.type] || newContentData();
contentData.requests += 1;
// header vs content size?
// Firefox sometimes has asset size -1 in HAR files
contentData.transferSize += Math.max(asset.transferSize, 0);
contentData.contentSize += Math.max(asset.contentSize, 0);
contentData.headerSize += Math.max(asset.headerSize, 0);

contentData.requests += 1;
// header vs content size?
// Firefox sometimes has asset size -1 in HAR files
contentData.transferSize += Math.max(asset.transferSize, 0);
contentData.contentSize += Math.max(asset.contentSize, 0);
contentData.headerSize += Math.max(asset.headerSize, 0);

contentTypes[asset.type] = contentData;
contentTypes[asset.type] = contentData;
}
}
};
1 change: 1 addition & 0 deletions test/files/responseCodes/304.har

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions test/responseCodesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
let assert = require('assert');
let har = require('./helpers/har');


describe('Resonse codes', function() {

it('We should be able identify all response codes', function() {
return har.pagesFromTestHar('redirect/aftonbladet.se-redirecting-to-www.har')
.then((result) => {
return har
.pagesFromTestHar('redirect/aftonbladet.se-redirecting-to-www.har')
.then(result => {
assert.strictEqual(result[0].responseCodes[200], 168, '200');
assert.strictEqual(result[0].responseCodes[404], 1, '404');
assert.strictEqual(result[0].responseCodes[301], 1, '301');
assert.strictEqual(result[0].responseCodes[204], 2, '204');
});
});


it('304 should be included in the page size', function() {
return har.pagesFromTestHar('responseCodes/304.har').then(result => {
console.log(result[0].contentTypes.css);
console.log(result[0].contentTypes.javascript);
});
});
});