public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
{
$response = $next($request, $response);
$cacheControl = $response->getHeaderLine('Cache-Control') ?: '';
if (stripos($cacheControl, 'max-age') === false) {
$mime = Utils\Helpers::getMimeType($response);
$expires = new DateTimeImmutable(isset($this->expires[$mime]) ? $this->expires[$mime] : $this->expiresDefault);
$cacheControl .= ' max-age=' . ($expires->getTimestamp() - time());
return $response->withHeader('Cache-Control', trim($cacheControl))->withHeader('Expires', $expires->format('D, d M Y H:i:s') . ' GMT');
}
return $response;
}