setHeader() 공개 메소드

Sends a HTTP header and replaces a previous one.
public setHeader ( $name, $value ) : void
리턴 void
예제 #1
0
 /**
  * Sends chunked response to output.
  *
  * @param \MouseOver\Storage\IStorageFile $storageFile  Storage file
  * @param \Nette\Http\IRequest            $httpRequest  HTTP request
  * @param \Nette\Http\IResponse           $httpResponse HTTP response
  *
  * @return void
  */
 protected function sendStorageFile($storageFile, Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setHeader('Accept-Ranges', 'bytes');
     $reader = $storageFile->getReader();
     if (preg_match('#^bytes=(\\d*)-(\\d*)\\z#', $httpRequest->getHeader('Range'), $matches)) {
         list(, $start, $end) = $matches;
         if ($start === '') {
             $start = null;
         }
         if ($end === '') {
             $end = null;
         }
         try {
             $reader->setRange($start, $end);
         } catch (\InvalidArgumentException $invalidArgumentException) {
             $httpResponse->setCode(416);
             // requested range not satisfiable
             return;
         }
         $httpResponse->setCode(206);
         $httpResponse->setHeader('Content-Range', 'bytes ' . $reader->getRangeStart() . '-' . $reader->getRangeEnd() . '/' . $reader->getFileSize());
         $reader->setRange($start, $end);
         $httpResponse->setHeader('Content-Length', $reader->getLength());
     } else {
         $httpResponse->setHeader('Content-Range', 'bytes 0-' . ($reader->getFileSize() - 1) . '/' . $reader->getFileSize());
         $httpResponse->setHeader('Content-Length', $reader->getLength());
     }
     while ($reader->hasContent()) {
         echo $reader->read();
     }
 }
예제 #2
0
 public function generateImage(ImageRequest $request)
 {
     $width = $request->getWidth();
     $height = $request->getHeight();
     $format = $request->getFormat();
     if (!$this->validator->validate($width, $height)) {
         throw new Application\BadRequestException();
     }
     $image = NULL;
     foreach ($this->providers as $provider) {
         $image = $provider->getImage($request);
         if ($image) {
             break;
         }
     }
     if (!$image) {
         $this->httpResponse->setHeader('Content-Type', 'image/jpeg');
         $this->httpResponse->setCode(Http\IResponse::S404_NOT_FOUND);
         exit;
     }
     $destination = $this->wwwDir . '/' . $this->httpRequest->getUrl()->getRelativeUrl();
     $dirname = dirname($destination);
     if (!is_dir($dirname)) {
         $success = @mkdir($dirname, 0777, TRUE);
         if (!$success) {
             throw new Application\BadRequestException();
         }
     }
     $success = $image->save($destination, 90, $format);
     if (!$success) {
         throw new Application\BadRequestException();
     }
     $image->send();
     exit;
 }
예제 #3
0
 /**
  * Check allowed methods
  *
  * @throws BadRequestException If method is not supported but another one can be used
  */
 protected function checkAllowedMethods()
 {
     $availableMethods = $this->methods->getOptions($this->request->getUrl());
     if (!$availableMethods || in_array($this->request->method, $availableMethods)) {
         return;
     }
     $allow = implode(', ', $availableMethods);
     $this->response->setHeader('Allow', $allow);
     throw BadRequestException::methodNotSupported('Method not supported. Available methods: ' . $allow);
 }
예제 #4
0
 /**
  * Sends response to output.
  * @param IRequest   $request
  * @param IResponse  $response
  */
 public function send(IRequest $request, IResponse $response)
 {
     // Set response headers for the file download
     $response->setHeader('Content-Length', $this->stream->getSize());
     $response->setHeader('Content-Type', $this->contentType);
     $response->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '";');
     while (!$this->stream->eof()) {
         echo $this->stream->read(4000000.0);
     }
     $this->stream->close();
 }
예제 #5
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     if ($this->charset !== null) {
         $httpResponse->setContentType($this->contentType);
         $httpResponse->setContentType($this->contentType . ';charset=' . $this->charset);
     } else {
         $httpResponse->setContentType($this->contentType);
     }
     $httpResponse->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '"');
     $length = strlen($this->data);
     $httpResponse->setHeader('Content-Length', $length);
     echo $this->data;
 }
예제 #6
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);
 }
예제 #7
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"' . '; filename*=utf-8\'\'' . rawurlencode($this->name));
     $length = strlen($this->data);
     /*
     		if ($this->resuming) {
     			$httpResponse->setHeader('Accept-Ranges', 'bytes');
     			if (preg_match('#^bytes=(\d*)-(\d*)\z#', $httpRequest->getHeader('Range'), $matches)) {
     				list(, $start, $end) = $matches;
     				if ($start === '') {
     					$start = max(0, $filesize - $end);
     					$end = $filesize - 1;
     
     				} elseif ($end === '' || $end > $filesize - 1) {
     					$end = $filesize - 1;
     				}
     				if ($end < $start) {
     					$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);
     echo $this->data;
 }
예제 #8
0
 /**
  * @param IRequest $httpRequest
  * @param IResponse $httpResponse
  * @return void
  */
 public function send(IRequest $httpRequest, IResponse $httpResponse)
 {
     $httpResponse->setCode($this->code);
     foreach ($this->headers as $name => $value) {
         $httpResponse->setHeader($name, $value);
     }
     echo (string) $this->getBody();
 }
예제 #9
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);
 }
예제 #10
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;
 }
예제 #11
0
 /**
  * Send error to image
  *
  * @param \Nette\Http\IResponse $response
  * @param string|\Exception $error
  */
 private function sendError(HttpResponse $response, $error, $width, $height)
 {
     $response->setCode(HttpResponse::S500_INTERNAL_SERVER_ERROR);
     $response->setContentType('image/gif');
     if (!$error instanceof \Exception) {
         $response->setHeader('X-Imager-Error-Message', $error);
     } else {
         $response->setHeader('X-Imager-Error-Message', get_class($error) . ': ' . $error->getMessage());
         // detailed information only in debug mode
         if ($this->factory->getDebugger()) {
             $response->setHeader('X-Imager-Error-File', $error->getFile() . ' (' . $error->getLine() . ')');
             $trace = $error->getTraceAsString();
             $trace = Strings::replace($trace, '~[\\n|\\n\\r]~', '>>>');
             $response->setHeader('X-Imager-Error-Trace', $trace);
         }
     }
     $this->factory->sendErrorImage($width, $height);
 }
예제 #12
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"');
     $output = NULL;
     if ($this->precalculateFileSize) {
         ob_start();
         Nette\Utils\Callback::invokeArgs($this->outputGenerator);
         $output = ob_get_clean();
         $filesize = $length = strlen($output);
     }
     if ($this->resuming && $this->precalculateFileSize) {
         $httpResponse->setHeader('Accept-Ranges', 'bytes');
         if (preg_match('#^bytes=(\\d*)-(\\d*)\\z#', $httpRequest->getHeader('Range'), $matches)) {
             list(, $start, $end) = $matches;
             if ($start === '') {
                 $start = max(0, $filesize - $end);
                 $end = $filesize - 1;
             } elseif ($end === '' || $end > $filesize - 1) {
                 $end = $filesize - 1;
             }
             if ($end < $start) {
                 $httpResponse->setCode(416);
                 // requested range not satisfiable
                 return;
             }
             $httpResponse->setCode(206);
             $httpResponse->setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $filesize);
             $length = $end - $start + 1;
         } else {
             $httpResponse->setHeader('Content-Range', 'bytes 0-' . ($filesize - 1) . '/' . $filesize);
         }
     }
     if ($this->precalculateFileSize) {
         $httpResponse->setHeader('Content-Length', $length);
     }
     if (isset($start)) {
         echo substr($output, $start, $length);
     } elseif (isset($output)) {
         echo $output;
     } else {
         Nette\Utils\Callback::invoke($this->outputGenerator);
     }
 }
예제 #13
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)
 {
     /**
      * Disable tracy bar
      */
     if (class_exists('\\Tracy\\Debugger') && property_exists('\\Tracy\\Debugger', 'productionMode')) {
         \Tracy\Debugger::$productionMode = TRUE;
     }
     /**
      * Set Content-Type header
      */
     $httpResponse->setContentType($this->contentType, $this->output_encoding);
     /**
      * Set Content-Disposition header
      */
     $httpResponse->setHeader('Content-Disposition', 'attachment' . '; filename="' . $this->name . '"');
     /*. '; filename*=' . $this->output_encoding . '\'\'' . rawurlencode($this->name));*/
     /**
      * Set other headers
      */
     foreach ($this->headers as $key => $value) {
         $httpResponse->setHeader($key, $value);
     }
     if (function_exists('ob_start')) {
         ob_start();
     }
     /**
      * Output data
      */
     $delimiter = '"' . $this->delimiter . '"';
     foreach ($this->data as $row) {
         if (strtolower($this->output_encoding) == 'utf-8') {
             echo '"' . implode($delimiter, (array) $row) . '"';
         } else {
             echo iconv('UTF-8', $this->output_encoding, '"' . implode($delimiter, (array) $row) . '"');
         }
         echo "\r\n";
     }
     if (function_exists('ob_end_flush')) {
         ob_end_flush();
     }
 }
예제 #14
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
	 * @return bool
	 */
	public function isModified($lastModified = NULL, $etag = NULL)
	{
		if ($lastModified) {
			$this->response->setHeader('Last-Modified', $this->response->date($lastModified));
		}
		if ($etag) {
			$this->response->setHeader('ETag', '"' . addslashes($etag) . '"');
		}

		$ifNoneMatch = $this->request->getHeader('If-None-Match');
		if ($ifNoneMatch === '*') {
			$match = TRUE; // match, check if-modified-since

		} elseif ($ifNoneMatch !== NULL) {
			$etag = $this->response->getHeader('ETag');

			if ($etag == NULL || strpos(' ' . strtr($ifNoneMatch, ",\t", '  '), ' ' . $etag) === FALSE) {
				return TRUE;

			} else {
				$match = TRUE; // match, check if-modified-since
			}
		}

		$ifModifiedSince = $this->request->getHeader('If-Modified-Since');
		if ($ifModifiedSince !== NULL) {
			$lastModified = $this->response->getHeader('Last-Modified');
			if ($lastModified != NULL && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
				$match = TRUE;

			} else {
				return TRUE;
			}
		}

		if (empty($match)) {
			return TRUE;
		}

		$this->response->setCode(IResponse::S304_NOT_MODIFIED);
		return FALSE;
	}
예제 #15
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;
 }
예제 #16
0
 /**
  * Sends response to output.
  * @param Nette\Http\IRequest  $httpRequest
  * @param Nette\Http\IResponse $httpResponse
  */
 function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType('application/pdf');
     $httpResponse->setHeader('Content-Disposition', 'inline; filename="' . basename($this->filePath) . '"');
     $httpResponse->setHeader('Content-Description', 'File Transfer');
     $httpResponse->setHeader('Connection', 'Keep-Alive');
     $httpResponse->setHeader('Expires', '0');
     $httpResponse->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
     $httpResponse->setHeader('Pragma', 'public');
     $httpResponse->setHeader('Content-Length', filesize($this->filePath));
     readfile($this->filePath);
 }
예제 #17
0
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '"');
     $filesize = $length = filesize($this->file);
     $handle = fopen($this->file, 'r');
     if ($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);
     while (!feof($handle)) {
         echo fread($handle, 4000000.0);
     }
     fclose($handle);
 }
 /**
  * Sends response to output.
  *
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '"');
     $filesize = $length = filesize($this->file);
     $handle = fopen($this->file, 'r');
     if ($this->resuming) {
         $httpResponse->setHeader('Accept-Ranges', 'bytes');
         if (preg_match('#^bytes=(\\d*)-(\\d*)$#', $httpRequest->getHeader('Range'), $matches)) {
             list(, $start, $end) = $matches;
             if ($start === '') {
                 $start = max(0, $filesize - $end);
                 $end = $filesize - 1;
             } elseif ($end === '' || $end > $filesize - 1) {
                 $end = $filesize - 1;
             }
             if ($end <= $start) {
                 $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);
     while (!feof($handle) && $length > 0) {
         echo $s = fread($handle, min(4000000.0, $length));
         $length -= strlen($s);
     }
     fclose($handle);
 }
예제 #19
0
파일: FDTools.php 프로젝트: OCC2/occ2pacs
 /**
  * Clears all http headers
  * @param IResponse $res
  * @return IResponse
  */
 static function clearHeaders(IResponse $res, $setContentType = false)
 {
     $res->setCode(IResponse::S200_OK);
     foreach ($res->getHeaders() as $key => $val) {
         $res->setHeader($key, null);
     }
     if ($setContentType === true) {
         $res->setContentType("text/html", "UTF-8");
     }
     return $res;
 }
예제 #20
0
 /**
  * Sets HTTP header for the response
  *
  * @param  string  header name
  * @param  string  header value
  * @return self
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setHeader($name, $value)
 {
     $this->httpResponse->setHeader($name, $value);
     return $this;
 }
예제 #21
0
파일: Export.php 프로젝트: bombush/NatsuCon
 /**
  * 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)
 {
     $encoding = 'utf-8';
     $label = $this->label ? ucfirst(Strings::webalize($this->label)) : ucfirst($this->grid->name);
     $httpResponse->setHeader('Content-Encoding', $encoding);
     $httpResponse->setHeader('Content-Type', "text/csv; charset={$encoding}");
     $httpResponse->setHeader('Content-Disposition', "attachment; filename=\"{$label}.csv\"");
     print chr(0xef) . chr(0xbb) . chr(0xbf);
     //UTF-8 BOM
     $this->printCsv();
 }
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"' . '; filename*=utf-8\'\'' . rawurlencode($this->name));
     echo $this->fileContent;
 }
예제 #23
0
 /**
  * @param Nette\Http\IRequest $httpRequest
  * @param Nette\Http\IResponse $httpResponse
  */
 function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $response = $this->getResponse();
     $httpResponse->setCode(200);
     $httpResponse->setContentType('text/plain');
     $httpResponse->setHeader('Content-Length', strlen($response));
     echo $response;
 }
예제 #24
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($this->contentType, $this->outputCharset);
     $attachment = 'attachment';
     if (!empty($this->filename)) {
         $attachment .= '; filename="' . $this->filename . '"';
     }
     $httpResponse->setHeader('Content-Disposition', $attachment);
     $data = $this->formatCsv();
     $httpResponse->setHeader('Content-Length', strlen($data));
     print $data;
 }
예제 #25
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->setHeader('Content-type', 'image/jpeg');
     imagejpeg($this->image, $this->filename, $this->quality);
     imagedestroy($this->image);
 }
예제 #26
0
 /**
  * @param IRequest $request
  * @param IResponse $response
  * @return void
  */
 public function send(IRequest $request, IResponse $response)
 {
     $response->setContentType($this->contentType);
     $response->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->filename . '"' . '; filename*=utf-8\'\'' . rawurlencode($this->filename));
     $this->adapter->send($request, $response);
 }
예제 #27
0
파일: Export.php 프로젝트: novotnej/grido
 /**
  * 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)
 {
     $encoding = 'UTF-16LE';
     $file = $this->label . '.csv';
     $source = $this->generateSource();
     $source = mb_convert_encoding($source, $encoding, 'UTF-8');
     $source = "ÿþ" . $source;
     //add BOM
     $httpResponse->setHeader('Content-Encoding', $encoding);
     $httpResponse->setHeader('Content-Length', mb_strlen($source, $encoding));
     $httpResponse->setHeader('Content-Type', "text/csv; charset={$encoding}");
     $httpResponse->setHeader('Content-Disposition', "attachment; filename=\"{$file}\"; filename*=utf-8''{$file}");
     print $source;
 }
예제 #28
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;
 }
예제 #29
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);
 }
예제 #30
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();
 }