Use `Header::normalize()` in `RequestHandler::sendPsr7Response()`
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 11 May 2022 10:46:01 +0000 (12:46 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 12 May 2022 08:43:14 +0000 (10:43 +0200)
see #4534

wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index 5dbcb3f313df7c08fbdf60e84baf4ddba80d1fdb..bd9f609d0e59a8db3212232ee269c9f1e5c6d53b 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\system\request;
 
+use GuzzleHttp\Psr7\Header;
 use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
 use Psr\Http\Message\ResponseInterface;
 use wcf\system\application\ApplicationHandler;
@@ -114,52 +115,6 @@ class RequestHandler extends SingletonFactory
         }
     }
 
-    /**
-     * Splits the given array of cache-control values at commas, while properly
-     * taking into account that each value might itself contain commas within a
-     * quoted string.
-     */
-    private function splitCacheControl(array $values): \Iterator
-    {
-        foreach ($values as $value) {
-            $isQuoted = false;
-            $result = '';
-
-            for ($i = 0, $len = \strlen($value); $i < $len; $i++) {
-                $char = $value[$i];
-                if (!$isQuoted && $char === ',') {
-                    yield \trim($result);
-
-                    $isQuoted = false;
-                    $result = '';
-
-                    continue;
-                }
-
-                if ($isQuoted && $char === '\\') {
-                    $result .= $char;
-                    $i++;
-
-                    if ($i < $len) {
-                        $result .= $value[$i];
-
-                        continue;
-                    }
-                }
-
-                if ($char === '"') {
-                    $isQuoted = !$isQuoted;
-                }
-
-                $result .= $char;
-            }
-
-            if ($result !== '') {
-                yield \trim($result);
-            }
-        }
-    }
-
     /**
      * @since 5.5
      */
@@ -170,7 +125,7 @@ class RequestHandler extends SingletonFactory
         $cacheControl = [
             'private',
         ];
-        foreach ($this->splitCacheControl($response->getHeader('cache-control')) as $value) {
+        foreach (Header::normalize($response->getHeader('cache-control')) as $value) {
             [$field] = \explode('=', $value, 2);
 
             // Prevent duplication of the 'private' field.