From 930c7cb94c7957a8572bdbdef2ad5d113d99da9e Mon Sep 17 00:00:00 2001 From: Daniel Jagszent Date: Tue, 14 Dec 2021 17:00:44 +0100 Subject: [PATCH] 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. --- Diagnostic/MatomoJsCheck.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Diagnostic/MatomoJsCheck.php b/Diagnostic/MatomoJsCheck.php index 0630467..ff42f24 100644 --- a/Diagnostic/MatomoJsCheck.php +++ b/Diagnostic/MatomoJsCheck.php @@ -68,8 +68,8 @@ class MatomoJsCheck implements Diagnostic if ( $status != 200 || strpos($data, "c80d50af7d3db9be66a4d0a86db0286e4fd33292") === false - || empty($headers["content-type"]) - || empty($headers["content-encoding"]) + || empty($headers["Content-Type"]) + || empty($headers["Vary"]) ) { $result = new DiagnosticResult($this->label); $result->addItem(new DiagnosticResultItem( @@ -82,8 +82,8 @@ class MatomoJsCheck implements Diagnostic return [$result]; } $results = new DiagnosticResult($this->label); - $contentType = $headers["content-type"]; - if ($contentType !== "application/javascript") { + $contentType = $headers["Content-Type"]; + if (strpos($contentType, "application/javascript") !== 0) { $results->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_WARNING, Piwik::translate("DiagnosticsExtended_MatomoJSCheckMIMEError", @@ -91,8 +91,8 @@ class MatomoJsCheck implements Diagnostic )); } - $contentEncoding = $headers["content-encoding"]; - if ($contentEncoding === "gzip" || $contentEncoding === "br") { + $vary = strtolower($headers["Vary"]); + if (strpos($vary, 'accept-encoding') !== false) { $results->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_OK, Piwik::translate("DiagnosticsExtended_MatomoJSCheckGzipped")