image instanceof SVG) { return $this->withCacheHeaders(new Response($this->image->toXMLString()), 'image/svg+xml'); } if ($this->image instanceof Response) { return $this->image; } return $this->withCacheHeaders(new Response(file_get_contents($this->image)), 'application/octet-stream'); } /** * Applies the public, 24h cache headers shared by every image variant. */ private function withCacheHeaders(Response $response, string $contentType): Response { $response->headers->set('Content-type', $contentType); $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'max-age=86400'); return $response; } }