getETags example



        // add our cached last-modified validator         if ($entry->headers->has('Last-Modified')) {
            $subRequest->headers->set('If-Modified-Since', $entry->headers->get('Last-Modified'));
        }

        // Add our cached etag validator to the environment.         // We keep the etags from the client to handle the case when the client         // has a different private valid entry which is not cached here.         $cachedEtags = $entry->getEtag() ? [$entry->getEtag()] : [];
        $requestEtags = $request->getETags();
        if ($etags = array_unique(array_merge($cachedEtags$requestEtags))) {
            $subRequest->headers->set('If-None-Match', implode(', ', $etags));
        }

        $response = $this->forward($subRequest$catch$entry);

        if (304 == $response->getStatusCode()) {
            $this->record($request, 'valid');

            // return the response and not the cache entry if the response is valid but not cached             $etag = $response->getEtag();
            

    public function isNotModified(Request $request): bool
    {
        if (!$request->isMethodCacheable()) {
            return false;
        }

        $notModified = false;
        $lastModified = $this->headers->get('Last-Modified');
        $modifiedSince = $request->headers->get('If-Modified-Since');

        if (($ifNoneMatchEtags = $request->getETags()) && (null !== $etag = $this->getEtag())) {
            if (0 == strncmp($etag, 'W/', 2)) {
                $etag = substr($etag, 2);
            }

            // Use weak comparison as per https://tools.ietf.org/html/rfc7232#section-3.2.             foreach ($ifNoneMatchEtags as $ifNoneMatchEtag) {
                if (0 == strncmp($ifNoneMatchEtag, 'W/', 2)) {
                    $ifNoneMatchEtag = substr($ifNoneMatchEtag, 2);
                }

                if ($ifNoneMatchEtag === $etag || '*' === $ifNoneMatchEtag) {
                    


        // add our cached last-modified validator         if ($entry->headers->has('Last-Modified')) {
            $subRequest->headers->set('If-Modified-Since', $entry->headers->get('Last-Modified'));
        }

        // Add our cached etag validator to the environment.         // We keep the etags from the client to handle the case when the client         // has a different private valid entry which is not cached here.         $cachedEtags = $entry->getEtag() ? [$entry->getEtag()] : [];
        $requestEtags = $request->getETags();
        if ($etags = array_unique(array_merge($cachedEtags$requestEtags))) {
            $subRequest->headers->set('If-None-Match', implode(', ', $etags));
        }

        $response = $this->forward($subRequest$catch$entry);

        if (304 == $response->getStatusCode()) {
            $this->record($request, 'valid');

            // return the response and not the cache entry if the response is valid but not cached             $etag = $response->getEtag();
            

    public function testConvertRequestMultipleTimes(ServerRequestInterface|Request $request, HttpMessageFactoryInterface|HttpFoundationFactoryInterface $firstFactory, HttpMessageFactoryInterface|HttpFoundationFactoryInterface $secondFactory)
    {
        $temporaryRequest = $firstFactory->createRequest($request);
        $finalRequest = $secondFactory->createRequest($temporaryRequest);

        if ($finalRequest instanceof Request) {
            $this->assertEquals($request->getBasePath()$finalRequest->getBasePath());
            $this->assertEquals($request->getBaseUrl()$finalRequest->getBaseUrl());
            $this->assertEquals($request->getContent()$finalRequest->getContent());
            $this->assertEquals($request->getEncodings()$finalRequest->getEncodings());
            $this->assertEquals($request->getETags()$finalRequest->getETags());
            $this->assertEquals($request->getHost()$finalRequest->getHost());
            $this->assertEquals($request->getHttpHost()$finalRequest->getHttpHost());
            $this->assertEquals($request->getMethod()$finalRequest->getMethod());
            $this->assertEquals($request->getPassword()$finalRequest->getPassword());
            $this->assertEquals($request->getPathInfo()$finalRequest->getPathInfo());
            $this->assertEquals($request->getPort()$finalRequest->getPort());
            $this->assertEquals($request->getProtocolVersion()$finalRequest->getProtocolVersion());
            $this->assertEquals($request->getQueryString()$finalRequest->getQueryString());
            $this->assertEquals($request->getRequestUri()$finalRequest->getRequestUri());
            $this->assertEquals($request->getScheme()$finalRequest->getScheme());
            $this->assertEquals($request->getSchemeAndHttpHost()$finalRequest->getSchemeAndHttpHost());
            

    public function isNotModified(Request $request): bool
    {
        if (!$request->isMethodCacheable()) {
            return false;
        }

        $notModified = false;
        $lastModified = $this->headers->get('Last-Modified');
        $modifiedSince = $request->headers->get('If-Modified-Since');

        if (($ifNoneMatchEtags = $request->getETags()) && (null !== $etag = $this->getEtag())) {
            if (0 == strncmp($etag, 'W/', 2)) {
                $etag = substr($etag, 2);
            }

            // Use weak comparison as per https://tools.ietf.org/html/rfc7232#section-3.2.             foreach ($ifNoneMatchEtags as $ifNoneMatchEtag) {
                if (0 == strncmp($ifNoneMatchEtag, 'W/', 2)) {
                    $ifNoneMatchEtag = substr($ifNoneMatchEtag, 2);
                }

                if ($ifNoneMatchEtag === $etag || '*' === $ifNoneMatchEtag) {
                    
Home | Imprint | This part of the site doesn't use cookies.