Ejemplo n.º 1
0
 /**
  * Check Cache
  *
  * Checks the browser cache to see the response needs to be returned
  *
  * @param   string   $etag     Resource ETag [Optional]
  * @param   Request  $request  The request to test against [Optional]
  *
  * @return  Response
  *
  * @throws  Request_Exception
  */
 public function check_cache($etag = NULL, Request $request = NULL)
 {
     if (!$etag) {
         $etag = $this->generate_etag();
     }
     if (!$request) {
         throw new Request_Exception('A Request object must be supplied with an etag for evaluation');
     }
     // Set the ETag header
     $this->_header['etag'] = $etag;
     // Add the Cache-Control header if it is not already set
     // This allows etags to be used with max-age, etc
     if ($this->_header->offsetExists('cache-control')) {
         if (is_array($this->_header['cache-control'])) {
             // @todo
             $this->_header['cache-control'][] = new HTTP_Header_Value('must-revalidate');
         } else {
             $this->_header['cache-control'] = $this->_header['cache-control'] . ', must-revalidate';
         }
     } else {
         $this->_header['cache-control'] = 'must-revalidate';
     }
     if ($request->headers('if-none-match') and (string) $request->headers('if-none-match') === $etag) {
         // No need to send data again
         $this->_status = 304;
         $this->send_headers();
         // Stop execution
         exit;
     }
     return $this;
 }
Ejemplo n.º 2
0
 public function test_offsetExists(array $state, $key, $expected)
 {
     $header = new HTTP_Header($state);
     $this->assertSame($expected, $header->offsetExists($key));
 }
Ejemplo n.º 3
0
 /**
  * Gets or sets HTTP headers to the request or response. All headers
  * are included immediately after the HTTP protocol definition during
  * transmission. This method provides a simple array or key/value
  * interface to the headers.
  *
  * @param   mixed   $key   Key or array of key/value pairs to set
  * @param   string  $value Value to set to the supplied key
  *
  * @return  Request|HTTP_Header|mixed
  */
 public function headers($key = NULL, $value = NULL)
 {
     if ($key instanceof HTTP_Header) {
         // Act a setter, replace all headers
         $this->_header = $key;
         return $this;
     }
     if (is_array($key)) {
         // Act as a setter, replace all headers
         $this->_header->exchangeArray($key);
         return $this;
     }
     if ($this->_header->count() === 0 and $this->is_initial()) {
         // Lazy load the request headers
         $this->_header = HTTP::request_headers();
     }
     if ($key === NULL) {
         // Act as a getter, return all headers
         return $this->_header;
     } elseif ($value === NULL) {
         // Act as a getter, single header
         return $this->_header->offsetExists($key) ? $this->_header->offsetGet($key) : NULL;
     }
     // Act as a setter for a single header
     $this->_header[$key] = $value;
     return $this;
 }