Skip to content

Commit

Permalink
Include the size of 304 responses see sitespeedio/sitespeed.io#1963 (#60
Browse files Browse the repository at this point in the history
)
  • Loading branch information
soulgalore authored Mar 28, 2018
1 parent 16d68f5 commit cc6ae6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
24 changes: 10 additions & 14 deletions lib/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,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);
});
});
});

0 comments on commit cc6ae6e

Please sign in to comment.