Namespaces

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • Ftp
  • Html
  • HttpContext
  • HttpRequest
  • HttpResponse
  • HttpUploadedFile
  • Session
  • SessionNamespace
  • Uri
  • UriScript
  • User

Interfaces

  • IHttpRequest
  • IHttpResponse
  • IUser

Exceptions

  • FtpException
  • Overview
  • Namespace
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Web;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * HTTP-specific tasks.
 20:  *
 21:  * @author     David Grudl
 22:  */
 23: class HttpContext extends Nette\Object
 24: {
 25: 
 26: 
 27:     /**
 28:      * Attempts to cache the sent entity by its last modification date
 29:      * @param  string|int|DateTime  last modified time
 30:      * @param  string  strong entity tag validator
 31:      * @return bool
 32:      */
 33:     public function isModified($lastModified = NULL, $etag = NULL)
 34:     {
 35:         $response = $this->getResponse();
 36:         $request = $this->getRequest();
 37: 
 38:         if ($lastModified) {
 39:             $response->setHeader('Last-Modified', $response->date($lastModified));
 40:         }
 41:         if ($etag) {
 42:             $response->setHeader('ETag', '"' . addslashes($etag) . '"');
 43:         }
 44: 
 45:         $ifNoneMatch = $request->getHeader('If-None-Match');
 46:         if ($ifNoneMatch === '*') {
 47:             $match = TRUE; // match, check if-modified-since
 48: 
 49:         } elseif ($ifNoneMatch !== NULL) {
 50:             $etag = $response->getHeader('ETag');
 51: 
 52:             if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", '  '), ' ' . $etag) === FALSE) {
 53:                 return TRUE;
 54: 
 55:             } else {
 56:                 $match = TRUE; // match, check if-modified-since
 57:             }
 58:         }
 59: 
 60:         $ifModifiedSince = $request->getHeader('If-Modified-Since');
 61:         if ($ifModifiedSince !== NULL) {
 62:             $lastModified = $response->getHeader('Last-Modified');
 63:             if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
 64:                 $match = TRUE;
 65: 
 66:             } else {
 67:                 return TRUE;
 68:             }
 69:         }
 70: 
 71:         if (empty($match)) {
 72:             return TRUE;
 73:         }
 74: 
 75:         $response->setCode(IHttpResponse::S304_NOT_MODIFIED);
 76:         return FALSE;
 77:     }
 78: 
 79: 
 80: 
 81:     /********************* backend ****************d*g**/
 82: 
 83: 
 84: 
 85:     /**
 86:      * @return Nette\Web\IHttpRequest
 87:      */
 88:     public function getRequest()
 89:     {
 90:         return Nette\Environment::getHttpRequest();
 91:     }
 92: 
 93: 
 94: 
 95:     /**
 96:      * @return Nette\Web\IHttpResponse
 97:      */
 98:     public function getResponse()
 99:     {
100:         return Nette\Environment::getHttpResponse();
101:     }
102: 
103: }
104: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0