From 9aea4e567778fadd8f76814ce8a15bea19c0560d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Thu, 26 Nov 2020 01:37:29 +0100 Subject: [PATCH] New metrics: old HTTP and TLS protocols --- front/src/views/rule.html | 8 ++ lib/metadata/policies.js | 56 +++++++++----- lib/metadata/scoreProfileGeneric.json | 8 +- lib/rulesChecker.js | 3 +- lib/runner.js | 6 -- lib/tools/isHttp2.js | 105 -------------------------- package.json | 3 +- 7 files changed, 52 insertions(+), 137 deletions(-) delete mode 100644 lib/tools/isHttp2.js diff --git a/front/src/views/rule.html b/front/src/views/rule.html index 73ce778..0cf9911 100644 --- a/front/src/views/rule.html +++ b/front/src/views/rule.html @@ -175,6 +175,14 @@ ({{offender.size | bytes}}) + +
+ {{offender.domain}} receives over {{offender.httpVersion}} +
+ +
+ {{offender.domain}} uses {{offender.tlsVersion}} and seems to be on the critical path +
diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index 49bf3a4..befe3df 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -927,35 +927,55 @@ var policies = { return offenders; } },*/ - "http2": { - "label": "HTTP/2 or SPDY", - "message": "

HTTP/2 is the latest version of the HTTP protocol and is designed to optimize load speed. SPDY is deprecated but still very well supported.

The latest versions of all major browsers are now compatible. The difficulty is on the server side, where technologies are not quite ready yet.

", + "oldHttpProtocol": { + "label": "HTTP/1 requests", + "message": "

HTTP/2 is the latest version of the HTTP protocol. It is designed to optimize load speed. HTTP/3 will come soon and should be even faster!

When a domain sends more than 4 requests over HTTP/1, this metric counts one point for each new request. Below 5 requests, the benefits of HTTP/2 are generally less significant.

", "hasOffenders": true, "scoreFn": function(data) { - if (!data.toolsResults.http2) { - return null; + var count = 0; + + var offenders = data.toolsResults.phantomas.offenders.oldHttpProtocol; + + if (offenders) { + offenders.forEach(function(offender) { + if (offender.requests > 4) { + count += offender.requests - 4; + } + }); } - var isHttp2 = data.toolsResults.http2.metrics.http2; + var isOkThreshold = 0; + var isBadThreshold = 25; + var isAbnormalThreshold = 100; + var score = (isBadThreshold - count) * 100 / (isBadThreshold - isOkThreshold); + var abnormalityScore = (isAbnormalThreshold - count) * 100 / (isAbnormalThreshold - isOkThreshold); + + var result = { - value: isHttp2 ? 'Yes' : 'No', - score: isHttp2 ? 100 : 0, - bad: !isHttp2, - abnormal: false, - abnormalityScore: 0 + value: count, + score: Math.min(Math.max(Math.round(score), 0), 100), + bad: count > isBadThreshold, + abnormal: count > isAbnormalThreshold, + abnormalityScore: Math.min(Math.round(abnormalityScore), 0), + offendersObj: { + count: data.toolsResults.phantomas.metrics.oldHttpProtocol, + list: data.toolsResults.phantomas.offenders.oldHttpProtocol || [] + } }; - if (data.toolsResults.http2.offenders) { - result.offendersObj = { - count: data.toolsResults.http2.offenders.http2.length, - list: data.toolsResults.http2.offenders.http2 - }; - } - return result; } }, + "oldTlsProtocol": { + "tool": "phantomas", + "label": "Old TLS protocols", + "message": "

Counts the number of domains that use TLS versions < 1.3. This is the latest version and it includes a faster \"handshake\" technology.

The 1.0 and 1.1 versions are deprecated because they are unsafe, switch to 1.2 or above as soon as possible.

The version 1.3 includes an even faster option called 0-RTT, check your server compatibility on SSL Labs.

", + "isOkThreshold": 0, + "isBadThreshold": 5, + "isAbnormalThreshold": 15, + "hasOffenders": true + }, "cachingDisabled": { "tool": "phantomas", "label": "Caching disabled", diff --git a/lib/metadata/scoreProfileGeneric.json b/lib/metadata/scoreProfileGeneric.json index f9aa7a8..ab4abae 100644 --- a/lib/metadata/scoreProfileGeneric.json +++ b/lib/metadata/scoreProfileGeneric.json @@ -53,9 +53,7 @@ "label": "jQuery", "policies": { "jQueryVersion": 2, - "jQueryVersionsLoaded": 2, - "jQueryCallsOnEmptyObject": 1, - "jQueryNotDelegatedEvents": 1 + "jQueryVersionsLoaded": 2 } }, "cssComplexity": { @@ -95,7 +93,8 @@ "serverConfig": { "label": "Server config", "policies": { - "http2": 2, + "oldHttpProtocol": 2, + "oldTlsProtocol": 2, "closedConnections": 2, "cachingNotSpecified": 1, "cachingDisabled": 1, @@ -110,7 +109,6 @@ "javascriptComplexity": 2, "badJavascript": 2, "jQuery": 1, - "cssSyntaxError": 1, "cssComplexity": 1, "badCSS": 1, "fonts": 1, diff --git a/lib/rulesChecker.js b/lib/rulesChecker.js index bc570a7..eaffd6e 100644 --- a/lib/rulesChecker.js +++ b/lib/rulesChecker.js @@ -111,7 +111,8 @@ var RulesChecker = function() { if (rule) { rule.policy = { label: policy.label, - message: policy.message + message: policy.message, + hasOffenders: policy.hasOffenders || false }; results[metricName] = rule; diff --git a/lib/runner.js b/lib/runner.js index f0ba25b..93255e8 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -5,7 +5,6 @@ var phantomasWrapper = require('./tools/phantomas/phantomasWrapper'); var colorDiff = require('./tools/colorDiff'); var domAccessAgregator = require('./tools/domAccessAgregator'); var mediaQueriesChecker = require('./tools/mediaQueriesChecker'); -var isHttp2 = require('./tools/isHttp2'); var redownload = require('./tools/redownload/redownload'); var rulesChecker = require('./rulesChecker'); var scoreCalculator = require('./scoreCalculator'); @@ -42,11 +41,6 @@ var Runner = function(params) { }) - .then(function(data) { - // Check if HTTP2 - return isHttp2.check(data); - }) - .then(function(data) { // Rules checker diff --git a/lib/tools/isHttp2.js b/lib/tools/isHttp2.js deleted file mode 100644 index acea838..0000000 --- a/lib/tools/isHttp2.js +++ /dev/null @@ -1,105 +0,0 @@ -var debug = require('debug')('ylt:isHttp2'); -var url = require('url'); -var Q = require('q'); -var http2 = require('is-http2'); - -var isHttp2 = function() { - 'use strict'; - - this.check = function(data) { - debug('Starting to check for HTTP2 support...'); - - return this.checkHttp2(data) - - .then(function(result) { - - if (result.isHttp) { - debug('The website is not even in HTTPS'); - - data.toolsResults.http2 = { - metrics: { - http2: false - } - }; - - } else if (result.isHttp2) { - debug('HTTP/2 (or SPDY) is supported'); - - data.toolsResults.http2 = { - metrics: { - http2: true - } - }; - - } else { - debug('HTTP/2 is not supported'); - - data.toolsResults.http2 = { - metrics: { - http2: false - } - }; - } - - // Add the supported protocols as offenders - if (result.supportedProtocols) { - debug('Supported protocols: ' + result.supportedProtocols.join(' ')); - data.toolsResults.http2.offenders = { - http2: result.supportedProtocols - }; - } - - debug('End of HTTP2 support check'); - - return data; - }) - - .fail(function() { - return data; - }); - }; - - this.getParsedUrl = function(data) { - return url.parse(data.toolsResults.phantomas.url); - }; - - this.getProtocol = function(data) { - return this.getParsedUrl(data).protocol; - }; - - this.getDomain = function(data) { - return this.getParsedUrl(data).hostname; - }; - - this.checkHttp2 = function(data) { - var deferred = Q.defer(); - - // Check if it's HTTPS first - if (this.getProtocol(data) === 'http:') { - - deferred.resolve({ - isHttp: true - }); - - } else { - - // To make is-http2 work, you need to have openssl in a version greater than 1.0.0 installed and available in your $path. - http2(this.getDomain(data), {includeSpdy: true}) - - .then(function(result) { - deferred.resolve(result); - }) - - .catch(function(error) { - debug('Error while checking HTTP2 support:'); - debug(error); - deferred.reject('Error while checking for HTTP2 support'); - }); - - } - - return deferred.promise; - }; -}; - -module.exports = new isHttp2(); \ No newline at end of file diff --git a/package.json b/package.json index 4cd0bb2..92ae9fb 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "imagemin-svgo": "7.0.0", "is-eot": "1.0.0", "is-gif": "3.0.0", - "is-http2": "1.2.0", "is-jpg": "2.0.0", "is-otf": "0.1.2", "is-png": "1.1.0", @@ -62,7 +61,7 @@ "meow": "5.0.0", "minimize": "2.2.0", "parse-color": "1.0.0", - "phantomas": "2.0.0", + "phantomas": "github:macbre/phantomas#devel", "ps-node": "0.1.6", "q": "1.5.1", "request": "2.88.0",