本文整理汇总了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();
}
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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;
}