private function checkIfModified($lastModifiedTime)
 {
     if ($lastModifiedTime === false) {
         return false;
     }
     if (!$this->request->hasHeader('If-Modified-Since')) {
         return false;
     }
     $header = $this->request->getHeader('If-Modified-Since');
     $clientModifiedTime = @strtotime($header);
     if ($clientModifiedTime == false) {
         return false;
     }
     if ($clientModifiedTime < $lastModifiedTime) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
function cachedImageCallable(PageInfo $pageInfo, Request $request, Response $response, CachingFileResponseFactory $fileResponseFactory, $params)
{
    $filename = getImageCacheFilename($pageInfo, $params);
    $extensions = ["jpg", 'jpeg', "gif", "png"];
    $contentType = false;
    $filenameFound = false;
    foreach ($extensions as $extension) {
        $filenameWithExtension = $filename . "." . $extension;
        if (file_exists($filenameWithExtension) == true) {
            //TODO - content type should actually be image/jpeg
            $contentType = "image/" . $extension;
            $filenameFound = $filenameWithExtension;
            break;
        }
    }
    if ($filenameFound == false) {
        return false;
    }
    if ($request->hasHeader('HTTP_IF_MODIFIED_SINCE')) {
        $lastModifiedTime = filemtime($filenameFound);
        if (strtotime($request->getHeader('HTTP_IF_MODIFIED_SINCE')) >= $lastModifiedTime) {
            $response->setStatus(304);
            return new EmptyBody();
        }
    }
    return $fileResponseFactory->create($filenameFound, $contentType);
}