当前位置: 首页>>代码示例>>PHP>>正文


PHP IResponse::setHeader方法代码示例

本文整理汇总了PHP中Nette\Http\IResponse::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP IResponse::setHeader方法的具体用法?PHP IResponse::setHeader怎么用?PHP IResponse::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Http\IResponse的用法示例。


在下文中一共展示了IResponse::setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendStorageFile

 /**
  * 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();
     }
 }
开发者ID:mouse-over,项目名称:storage,代码行数:40,代码来源:StorageFileResponse.php

示例2: generateImage

 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;
 }
开发者ID:kuba1999,项目名称:nette-webimages,代码行数:35,代码来源:Generator.php

示例3: checkAllowedMethods

 /**
  * 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);
 }
开发者ID:lucien144,项目名称:Restful,代码行数:15,代码来源:MethodHandler.php

示例4: send

 /**
  * 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();
 }
开发者ID:ublaboo,项目名称:responses,代码行数:16,代码来源:PSR7StreamResponse.php

示例5: send

 /**
  * 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;
 }
开发者ID:bazo,项目名称:translation-ui,代码行数:17,代码来源:TextDownloadResponse.php

示例6: send

 /**
  * 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);
 }
开发者ID:ales-zrak,项目名称:assets-loader,代码行数:21,代码来源:FileResponse.php

示例7: send

 /**
  * 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;
 }
开发者ID:bkralik,项目名称:BarakIS,代码行数:38,代码来源:DownloadReponse.php

示例8: send

 /**
  * @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();
 }
开发者ID:lookyman,项目名称:nette-oauth2-server,代码行数:13,代码来源:Response.php

示例9: send

 /**
  * @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);
 }
开发者ID:dzibma,项目名称:rest-api,代码行数:12,代码来源:JsonResponse.php

示例10: send

 /**
  * {@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;
 }
开发者ID:tomaj,项目名称:nette-api,代码行数:11,代码来源:XmlApiResponse.php

示例11: sendError

 /**
  * 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);
 }
开发者ID:lawondyss,项目名称:imager,代码行数:24,代码来源:ImageResponse.php

示例12: send

 /**
  * 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);
     }
 }
开发者ID:instante,项目名称:responses,代码行数:48,代码来源:VirtualFileResponse.php

示例13: send

 /**
  * 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();
     }
 }
开发者ID:OCC2,项目名称:occ2pacs,代码行数:48,代码来源:CSVResponse.php

示例14: isModified

	/**
	 * 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;
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:48,代码来源:Context.php

示例15: send

 /**
  * 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;
 }
开发者ID:lohini,项目名称:webloader,代码行数:19,代码来源:WebLoaderResponse.php


注:本文中的Nette\Http\IResponse::setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。