setExpiration() public method

Sets the number of seconds before a page cached on a browser expires.
public setExpiration ( $seconds ) : void
return void
Exemplo n.º 1
0
 /**
  * {inheritDoc}
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->getContentType(), 'utf-8');
     $httpResponse->setExpiration(FALSE);
     $httpResponse->setCode($this->code);
     echo Nette\Utils\Json::encode($this->getPayload(), Nette\Utils\Json::PRETTY);
 }
Exemplo n.º 2
0
 /**
  * @param Http\IRequest $request
  * @param Http\IResponse $response
  */
 public function send(Http\IRequest $request, Http\IResponse $response)
 {
     $response->setContentType($this->contentType);
     $response->setCode($this->code ?: Http\IResponse::S200_OK);
     $response->setExpiration($this->expiration);
     $response->setHeader('Pragma', $this->expiration ? 'cache' : 'no-cache');
     echo Json::encode($this->data);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function send(IRequest $httpRequest, IResponse $httpResponse)
 {
     $httpResponse->setContentType('text/xml');
     $httpResponse->setExpiration(false);
     $httpResponse->setCode($this->getCode());
     $httpResponse->setHeader('Content-Length', strlen($this->response));
     echo $this->response;
 }
Exemplo n.º 4
0
 /**
  * Attempts to cache the sent entity by its last modification date.
  * @param  string|int|DateTime  last modified time
  * @param  string strong entity tag validator
  * @param  mixed  optional expiration time
  * @return void
  * @throws Nette\Application\AbortException
  */
 public function lastModified($lastModified, $etag = NULL, $expire = NULL)
 {
     if ($expire !== NULL) {
         $this->httpResponse->setExpiration($expire);
     }
     if (!$this->httpContext->isModified($lastModified, $etag)) {
         $this->terminate();
     }
 }
Exemplo n.º 5
0
 /**
  * Attempts to cache the sent entity by its last modification date.
  * @param  string|int|\DateTimeInterface  last modified time
  * @param  string strong entity tag validator
  * @param  mixed  optional expiration time
  * @return void
  * @throws Nette\Application\AbortException
  */
 public function lastModified($lastModified, $etag = NULL, $expire = NULL)
 {
     if ($expire !== NULL) {
         $this->httpResponse->setExpiration($expire);
     }
     $helper = new Http\Context($this->httpRequest, $this->httpResponse);
     if (!$helper->isModified($lastModified, $etag)) {
         $this->terminate();
     }
 }
Exemplo n.º 6
0
 /**
  * @param Nette\Http\IRequest $httpRequest
  * @param Nette\Http\IResponse $httpResponse
  * @throws \Nette\Application\BadRequestException
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setExpiration(FALSE);
     $callback = $httpRequest->getQuery(self::$callbackName);
     if (is_null($callback)) {
         throw new \Nette\Application\BadRequestException("Invalid JSONP request.");
     }
     echo $callback . "(" . Nette\Utils\Json::encode($this->payload) . ")";
 }
Exemplo n.º 7
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
 {
     if ($this->error) {
         $this->payload = ['error' => TRUE, 'message' => $this->errorMessage];
     } else {
         $this->payload['error'] = FALSE;
     }
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setExpiration(FALSE);
     echo Json::encode($this->payload);
 }
Exemplo n.º 8
0
 /**
  * Sends response to output.
  *
  * @param \Nette\Http\IRequest $httpRequest
  * @param \Nette\Http\IResponse $httpResponse
  */
 public function send(\Nette\Http\IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
 {
     if (strlen($this->etag)) {
         $httpResponse->setHeader('Etag', $this->etag);
     }
     $httpResponse->setExpiration(\Nette\Http\IResponse::PERMANENT);
     if (($inm = $httpRequest->getHeader('if-none-match')) && $inm == $this->etag) {
         $httpResponse->setCode(\Nette\Http\IResponse::S304_NOT_MODIFIED);
         return;
     }
     $httpResponse->setContentType($this->contentType);
     echo $this->content;
 }
Exemplo n.º 9
0
 /**
  * Sends response to output.
  *
  * @param Http\IRequest $httpRequest
  * @param Http\IResponse $httpResponse
  */
 public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
 {
     $httpResponse->setExpiration(Http\IResponse::PERMANENT);
     if (($inm = $httpRequest->getHeader('if-none-match')) && $inm == $this->etag) {
         $httpResponse->setCode(Http\IResponse::S304_NOT_MODIFIED);
         return;
     }
     $httpResponse->setContentType(AssetsLoader\Files\MimeMapper::getMimeFromFilename($this->filePath));
     $httpResponse->setHeader('Content-Transfer-Encoding', 'binary');
     $httpResponse->setHeader('Content-Length', filesize($this->filePath));
     $httpResponse->setHeader('Content-Disposition', 'attachment; filename="' . basename($this->filePath) . '"');
     $httpResponse->setHeader('Access-Control-Allow-Origin', '*');
     // Read the file
     readfile($this->filePath);
 }
Exemplo n.º 10
0
 /**
  * Sends response to output.
  * @param Nette\Http\IRequest $httpRequest
  * @param Nette\Http\IResponse $httpResponse
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setExpiration(FALSE);
     $response = array();
     $actual_url = $httpRequest->getUrl()->getAbsoluteUrl();
     date_default_timezone_set('UTC');
     //TODO: -1min
     $date = date('YmdHi');
     $hmac = hash_hmac('sha512', $actual_url . $date, 'PRIVATE_KEY');
     //TODO: na základě public key ($api_key)
     if ($this->payload['api_hash'] !== $hmac) {
         $response['err_code'] = 10;
         $response['err_info'] = $this->errors[10];
     }
     echo Nette\Utils\Json::encode($this->payload);
 }
Exemplo n.º 11
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setExpiration(FALSE);
     echo Nette\Utils\Json::encode($this->payload);
 }
Exemplo n.º 12
0
 /**
  * Sends response to output.
  * @param Nette\Http\IRequest  $httpRequest
  * @param Nette\Http\IResponse $httpResponse
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType('application/hal+json');
     $httpResponse->setExpiration(false);
     echo $this->json;
 }
Exemplo n.º 13
0
 /**
  * @param Http\IRequest $httpRequest
  * @param Http\IResponse $httpResponse
  */
 public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setCode($this->code);
     $httpResponse->setExpiration($this->expiration);
     $httpResponse->setHeader('Pragma', $this->expiration ? 'cache' : 'no-cache');
     $response = Json::encode($this->data);
     if (is_callable($this->postProcessor)) {
         $response = call_user_func($this->postProcessor, $response);
     }
     echo $response;
 }
Exemplo n.º 14
0
 /**
  * Send headers and outputs PDF document to browser.
  * @throws InvalidStateException
  */
 public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
 {
     $this->convert();
     $output = fgets($this->pipes[1], 5);
     if ($output === '%PDF') {
         $httpResponse->setContentType('application/pdf');
         if (strpos($httpRequest->getHeader('User-Agent'), 'MSIE') != FALSE) {
             $httpResponse->setHeader('Pragma', 'private');
             $httpResponse->setHeader('Cache-control', 'private');
             $httpResponse->setHeader('Accept-Ranges', 'bytes');
             $httpResponse->setExpiration('- 5 years');
         }
         echo $output;
         fpassthru($this->pipes[1]);
     }
     $this->close();
 }
Exemplo n.º 15
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $lastMTime = \filemtime($this->getFile());
     // Pokud je povoleno cachovani, podrzim to po dobu 14ti dnu (nebo dokud se soubor zmeni)
     if ($this->isCachingAllowed()) {
         $httpResponse->setExpiration(time() + 60 * 60 * 24 * 14);
         $cachedTime = $httpRequest->getHeader('If-Modified-Since');
         if ($cachedTime >= $lastMTime) {
             $httpResponse->setCode(304);
             return;
         }
     }
     if (!$this->dontSetContentType) {
         $httpResponse->setContentType($this->getContentType());
     }
     $httpResponse->addHeader("Last-Modified", gmdate("U", $lastMTime));
     $httpResponse->setHeader('Content-Disposition', $this->getContentDisposition() . '; filename="' . $this->getName() . '"');
     $filesize = $length = filesize($this->getFile());
     //$handle = fopen($this->getFile(), 'r');
     if (false && $this->resuming) {
         $httpResponse->setHeader('Accept-Ranges', 'bytes');
         $range = $httpRequest->getHeader('Range');
         if ($range !== NULL) {
             $range = substr($range, 6);
             // 6 == strlen('bytes=')
             list($start, $end) = explode('-', $range);
             if ($start == NULL) {
                 $start = 0;
             }
             if ($end == NULL) {
                 $end = $filesize - 1;
             }
             if ($start < 0 || $end <= $start || $end > $filesize - 1) {
                 $httpResponse->setCode(416);
                 // requested range not satisfiable
                 return;
             }
             $httpResponse->setCode(206);
             $httpResponse->setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $filesize);
             $length = $end - $start + 1;
             fseek($handle, $start);
         } else {
             $httpResponse->setHeader('Content-Range', 'bytes 0-' . ($filesize - 1) . '/' . $filesize);
         }
     }
     $httpResponse->setHeader('Content-Length', $length);
     readfile($this->getFile());
     //while(!feof($handle)) {
     //	echo fread($handle, 4e6);
     //}
     //fclose($handle);
 }
Exemplo n.º 16
0
 /**
  * Sends response to output.
  *
  * @param IRequest $httpRequest
  * @param IResponse $httpResponse
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setExpiration(FALSE);
     echo $this->encode($this->payload, $this->rootElement);
 }