setResponseFactory(new class implements ResponseFactoryInterface { public function create(FilesystemOperator $cache, string $path) { $stream = $cache->readStream($path); return new Response( stream_get_contents($stream), 200, [ 'Content-Type' => $cache->mimeType($path), 'Content-Length' => $cache->fileSize($path), 'Cache-Control' => 'public, max-age=31536000', ], ); } }); try { return $server->getImageResponse($path, $request->all()); } catch (FileNotFoundException $exception) { abort(404); } } }