Packages

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

Classes

  • NFtp
  • NHtml
  • NHttpContext
  • NHttpRequest
  • NHttpResponse
  • NHttpUploadedFile
  • NSession
  • NSessionNamespace
  • NUri
  • NUriScript
  • NUser

Interfaces

  • IHttpRequest
  • IHttpResponse
  • IUser

Exceptions

  • NFtpException
  • Overview
  • Package
  • 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:  * @package Nette\Web
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * HTTP-specific tasks.
 17:  *
 18:  * @author     David Grudl
 19:  * @package Nette\Web
 20:  */
 21: class NHttpContext extends NObject
 22: {
 23: 
 24: 
 25:     /**
 26:      * Attempts to cache the sent entity by its last modification date
 27:      * @param  string|int|DateTime  last modified time
 28:      * @param  string  strong entity tag validator
 29:      * @return bool
 30:      */
 31:     public function isModified($lastModified = NULL, $etag = NULL)
 32:     {
 33:         $response = $this->getResponse();
 34:         $request = $this->getRequest();
 35: 
 36:         if ($lastModified) {
 37:             $response->setHeader('Last-Modified', $response->date($lastModified));
 38:         }
 39:         if ($etag) {
 40:             $response->setHeader('ETag', '"' . addslashes($etag) . '"');
 41:         }
 42: 
 43:         $ifNoneMatch = $request->getHeader('If-None-Match');
 44:         if ($ifNoneMatch === '*') {
 45:             $match = TRUE; // match, check if-modified-since
 46: 
 47:         } elseif ($ifNoneMatch !== NULL) {
 48:             $etag = $response->getHeader('ETag');
 49: 
 50:             if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", '  '), ' ' . $etag) === FALSE) {
 51:                 return TRUE;
 52: 
 53:             } else {
 54:                 $match = TRUE; // match, check if-modified-since
 55:             }
 56:         }
 57: 
 58:         $ifModifiedSince = $request->getHeader('If-Modified-Since');
 59:         if ($ifModifiedSince !== NULL) {
 60:             $lastModified = $response->getHeader('Last-Modified');
 61:             if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
 62:                 $match = TRUE;
 63: 
 64:             } else {
 65:                 return TRUE;
 66:             }
 67:         }
 68: 
 69:         if (empty($match)) {
 70:             return TRUE;
 71:         }
 72: 
 73:         $response->setCode(IHttpResponse::S304_NOT_MODIFIED);
 74:         return FALSE;
 75:     }
 76: 
 77: 
 78: 
 79:     /********************* backend ****************d*g**/
 80: 
 81: 
 82: 
 83:     /**
 84:      * @return IHttpRequest
 85:      */
 86:     public function getRequest()
 87:     {
 88:         return NEnvironment::getHttpRequest();
 89:     }
 90: 
 91: 
 92: 
 93:     /**
 94:      * @return IHttpResponse
 95:      */
 96:     public function getResponse()
 97:     {
 98:         return NEnvironment::getHttpResponse();
 99:     }
100: 
101: }
102: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0