Packages

  • Nette
    • Application
      • Application\Diagnostics
      • Application\Responses
      • Application\Routers
      • Application\UI
    • Caching
      • Caching\Storages
    • ComponentModel
    • Config
    • Database
      • Database\Diagnostics
      • Database\Drivers
      • Database\Reflection
      • Database\Table
    • DI
    • Diagnostics
    • Forms
      • Forms\Controls
      • Forms\Rendering
    • Http
    • Iterators
    • Latte
      • Latte\Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • NHttpContext
  • NHttpRequest
  • NHttpRequestFactory
  • NHttpResponse
  • NHttpUploadedFile
  • NSession
  • NSessionSection
  • NUrl
  • NUrlScript
  • NUser

Interfaces

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