setAutoLastModified example

$request = Request::create('/');
        $response->prepare($request);

        $this->assertSame(200, $response->getStatusCode());
        $this->assertSame('image/gif', $response->headers->get('Content-Type'));
    }

    public function testContentTypeIsNotGuessedWhenTheFileWasNotModified()
    {
        $response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif');
        $response->setAutoLastModified();

        $request = Request::create('/');
        $request->headers->set('If-Modified-Since', $response->getLastModified()->format('D, d M Y H:i:s').' GMT');
        $isNotModified = $response->isNotModified($request);
        $this->assertTrue($isNotModified);
        $response->prepare($request);

        $this->assertSame(304, $response->getStatusCode());
        $this->assertFalse($response->headers->has('Content-Type'));
    }

    
if (!$file->isReadable()) {
            throw new FileException('File must be readable.');
        }

        $this->file = $file;

        if ($autoEtag) {
            $this->setAutoEtag();
        }

        if ($autoLastModified) {
            $this->setAutoLastModified();
        }

        if ($contentDisposition) {
            $this->setContentDisposition($contentDisposition);
        }

        return $this;
    }

    /** * Gets the file. */
if (!$file->isReadable()) {
            throw new FileException('File must be readable.');
        }

        $this->file = $file;

        if ($autoEtag) {
            $this->setAutoEtag();
        }

        if ($autoLastModified) {
            $this->setAutoLastModified();
        }

        if ($contentDisposition) {
            $this->setContentDisposition($contentDisposition);
        }

        return $this;
    }

    /** * Gets the file. */
Home | Imprint | This part of the site doesn't use cookies.