From: Tim Düsterhus Date: Wed, 11 May 2022 10:46:01 +0000 (+0200) Subject: Use `Header::normalize()` in `RequestHandler::sendPsr7Response()` X-Git-Tag: 6.0.0_Alpha_1~1326^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bbae05da18cb5e00eb1f8098b4bbc40449dac1ab;p=GitHub%2FWoltLab%2FWCF.git Use `Header::normalize()` in `RequestHandler::sendPsr7Response()` see #4534 --- diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 5dbcb3f313..bd9f609d0e 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -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.