1
0
Fork 0
mirror of https://github.com/Findus23/matomo-DiagnosticsExtended.git synced 2024-09-19 16:03:46 +02:00

Update matomo.js check

Only HTTP/2 server use lowercase HTTP headers. Use capitalised header names for HTTP/1 support

Content Types like `application/javascript; charset=utf-8` should not trigger a warning.

Matomo's HTTP::sendHttpRequest does not send the required `Accept-Encoding` header. Standards compliant HTTP servers cannot send compressed output in this case. This change does the compression check by checking for the existence of the correct `Vary` header. Standards-compliant HTTP servers should send it when compression is possible.
This commit is contained in:
Daniel Jagszent 2021-12-14 17:00:44 +01:00 committed by GitHub
parent de2e384fc4
commit 930c7cb94c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,8 +68,8 @@ class MatomoJsCheck implements Diagnostic
if ( if (
$status != 200 $status != 200
|| strpos($data, "c80d50af7d3db9be66a4d0a86db0286e4fd33292") === false || strpos($data, "c80d50af7d3db9be66a4d0a86db0286e4fd33292") === false
|| empty($headers["content-type"]) || empty($headers["Content-Type"])
|| empty($headers["content-encoding"]) || empty($headers["Vary"])
) { ) {
$result = new DiagnosticResult($this->label); $result = new DiagnosticResult($this->label);
$result->addItem(new DiagnosticResultItem( $result->addItem(new DiagnosticResultItem(
@ -82,8 +82,8 @@ class MatomoJsCheck implements Diagnostic
return [$result]; return [$result];
} }
$results = new DiagnosticResult($this->label); $results = new DiagnosticResult($this->label);
$contentType = $headers["content-type"]; $contentType = $headers["Content-Type"];
if ($contentType !== "application/javascript") { if (strpos($contentType, "application/javascript") !== 0) {
$results->addItem(new DiagnosticResultItem( $results->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING, DiagnosticResult::STATUS_WARNING,
Piwik::translate("DiagnosticsExtended_MatomoJSCheckMIMEError", Piwik::translate("DiagnosticsExtended_MatomoJSCheckMIMEError",
@ -91,8 +91,8 @@ class MatomoJsCheck implements Diagnostic
)); ));
} }
$contentEncoding = $headers["content-encoding"]; $vary = strtolower($headers["Vary"]);
if ($contentEncoding === "gzip" || $contentEncoding === "br") { if (strpos($vary, 'accept-encoding') !== false) {
$results->addItem(new DiagnosticResultItem( $results->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_OK, DiagnosticResult::STATUS_OK,
Piwik::translate("DiagnosticsExtended_MatomoJSCheckGzipped") Piwik::translate("DiagnosticsExtended_MatomoJSCheckGzipped")