setImmutable example


        $response = new Response();
        $response->setPublic();

        $this->assertTrue($response->headers->hasCacheControlDirective('public'));
        $this->assertFalse($response->headers->hasCacheControlDirective('private'));
    }

    public function testSetImmutable()
    {
        $response = new Response();
        $response->setImmutable();

        $this->assertTrue($response->headers->hasCacheControlDirective('immutable'));
    }

    public function testIsImmutable()
    {
        $response = new Response();
        $response->setImmutable();

        $this->assertTrue($response->isImmutable());
    }

    
if (!$asset) {
            throw new NotFoundHttpException(sprintf('Asset with public path "%s" not found.', $pathInfo));
        }

        $mediaType = $this->getMediaType($asset->publicPath);
        $response = (new Response(
            $asset->content,
            headers: $mediaType ? ['Content-Type' => $mediaType] : [],
        ))
            ->setPublic()
            ->setMaxAge(604800)
            ->setImmutable()
            ->setEtag($asset->digest)
        ;

        $event->setResponse($response);
    }

    public static function getSubscribedEvents(): array
    {
        return [
            // priority higher than RouterListener             KernelEvents::REQUEST => [['onKernelRequest', 35]],
        ];
Home | Imprint | This part of the site doesn't use cookies.