config = $config; $this->apiService = $apiService; } /** * Displays the static asset by path. * * * @param array $params parameters or body of the request */ public function get(array $params): Response { $debug = (bool) $this->config->get('debug', false); $asset = $this->apiService->resolveStaticAsset($this->incomingRequest->getPathInfo(), $debug); if ($asset === false) { return new Response('', 404); } /** @var StaticAssetType $type */ $type = $asset['type']; return tap( new BinaryFileResponse($asset['path']), function (BinaryFileResponse $response) use ($type, $debug) { $response->headers->set('Content-Type', StaticAssetType::getMimeTypeByExtension($type)); // Only set Content-length when filesize() succeeds; on failure let // BinaryFileResponse compute it rather than advertising a bogus 0-length body. $size = filesize($response->getFile()->getPathname()); if ($size !== false) { $response->headers->set('Content-length', (string) $size); } if (in_array(true, [! $this->incomingRequest->query->has('id'), $debug])) { return; } $response->headers->set('Cache-Control', 'public, max-age=86500, immutable'); $response->headers->set('Pragma', 'public'); } ); } }