Addshore has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391787 )

Change subject: Fix SparqlHelper::getCacheMaxAge()
......................................................................

Fix SparqlHelper::getCacheMaxAge()

Some HTTP headers can be multi-valued, so
MWHttpRequest::getResponseHeaders() always returns an associative array
of *arrays*, not of single strings. We don’t expect multiple cache
headers, though, so let’s just always use the first one. (We can also
assume that MWHttpRequest won’t include empty arrays in the response
headers.)

Bug: T180665
Change-Id: I5e979cca8b82f39b51caff0e4f34b9e00bac8830
(cherry picked from commit 87806f3494d37a7a1895660ac8d63db56efbd9bb)
---
M includes/ConstraintCheck/Helper/SparqlHelper.php
M tests/phpunit/Helper/SparqlHelperTest.php
2 files changed, 5 insertions(+), 5 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/87/391787/1

diff --git a/includes/ConstraintCheck/Helper/SparqlHelper.php 
b/includes/ConstraintCheck/Helper/SparqlHelper.php
index d2593f4..9d922db 100644
--- a/includes/ConstraintCheck/Helper/SparqlHelper.php
+++ b/includes/ConstraintCheck/Helper/SparqlHelper.php
@@ -459,12 +459,12 @@
        public function getCacheMaxAge( $responseHeaders ) {
                if (
                        array_key_exists( 'x-cache-status', $responseHeaders ) 
&&
-                       preg_match( '/^hit(?:-.*)?$/', 
$responseHeaders['x-cache-status'] )
+                       preg_match( '/^hit(?:-.*)?$/', 
$responseHeaders['x-cache-status'][0] )
                ) {
                        $maxage = [];
                        if (
                                array_key_exists( 'cache-control', 
$responseHeaders ) &&
-                               preg_match( '/\bmax-age=(\d+)\b/', 
$responseHeaders['cache-control'], $maxage )
+                               preg_match( '/\bmax-age=(\d+)\b/', 
$responseHeaders['cache-control'][0], $maxage )
                        ) {
                                return intval( $maxage[1] );
                        } else {
diff --git a/tests/phpunit/Helper/SparqlHelperTest.php 
b/tests/phpunit/Helper/SparqlHelperTest.php
index 6068026..47274cf 100644
--- a/tests/phpunit/Helper/SparqlHelperTest.php
+++ b/tests/phpunit/Helper/SparqlHelperTest.php
@@ -446,15 +446,15 @@
         public function getCacheMaxAgeProvider() {
                 return [
                         'WDQS hit' => [
-                                [ 'x-cache-status' => 'hit-front', 
'cache-control' => 'public, max-age=300' ],
+                                [ 'x-cache-status' => [ 'hit-front' ], 
'cache-control' => [ 'public, max-age=300' ] ],
                                 300
                         ],
                         'WDQS miss' => [
-                                [ 'x-cache-status' => 'miss', 'cache-control' 
=> 'public, max-age=300' ],
+                                [ 'x-cache-status' => [ 'miss' ], 
'cache-control' => [ 'public, max-age=300' ] ],
                                 false
                         ],
                         'generic hit' => [
-                                [ 'x-cache-status' => 'hit' ],
+                                [ 'x-cache-status' => [ 'hit' ] ],
                                 true
                         ],
                 ];

-- 
To view, visit https://gerrit.wikimedia.org/r/391787
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e979cca8b82f39b51caff0e4f34b9e00bac8830
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: wmf/1.31.0-wmf.8
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to