Merge branch 'bugfix/icinga-web-2-doesn't-set-content-type-12161'

fixes #12161
This commit is contained in:
Noah Hilverling 2016-10-18 11:08:33 +02:00
commit 6a6d354539
3 changed files with 67 additions and 10 deletions

View File

@ -54,6 +54,13 @@ class Response extends Zend_Controller_Response_Http
*/
protected $rerenderLayout = false;
/**
* Content type of this response
*
* @var string
*/
protected $contentType = 'text/html';
/**
* Get the auto-refresh interval
*
@ -146,6 +153,31 @@ class Response extends Zend_Controller_Response_Http
return $this;
}
/**
* Get an array of all header values for the given name
*
* @param string $name The name of the header
* @param bool $lastOnly If this is true, the last value will be returned as a string
*
* @return null|array|string
*/
public function getHeader($name, $lastOnly = false)
{
$result = ($lastOnly ? null : array());
$headers = $this->getHeaders();
foreach ($headers as $header) {
if ($header['name'] === $name) {
if ($lastOnly) {
$result = $header['value'];
} else {
$result[] = $header['value'];
}
}
}
return $result;
}
/**
* Get the request
*
@ -205,6 +237,29 @@ class Response extends Zend_Controller_Response_Http
return $this;
}
/**
* Set the content type of this response
*
* @param string $contentType
*
* @return $this
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
return $this;
}
/**
* Get the content type of this response
*
* @return string
*/
public function getContentType()
{
return $this->contentType;
}
/**
* Entry point for HTTP responses in JSON format
*
@ -244,6 +299,10 @@ class Response extends Zend_Controller_Response_Http
$this->setRedirect($redirectUrl->getAbsoluteUrl());
}
}
if (! $this->getHeader('Content-Type', true)) {
$this->setHeader('Content-Type', $this->getContentType());
}
}
/**

View File

@ -67,6 +67,13 @@ class JsonResponse extends Response
*/
protected $successData;
/**
* Content type of this response
*
* @var string
*/
protected $contentType = 'application/json';
/**
* Get the JSON encoding options
*
@ -186,15 +193,6 @@ class JsonResponse extends Response
echo json_encode($body, $this->getEncodingOptions());
}
/**
* {@inheritdoc}
*/
public function sendHeaders()
{
$this->setHeader('Content-Type', 'application/json', true);
parent::sendHeaders();
}
/**
* {@inheritdoc}
*/

View File

@ -197,7 +197,7 @@ class StyleSheet
$response
->setHeader('Cache-Control', 'public', true)
->setHeader('ETag', $etag, true)
->setHeader('Content-Type', 'text/css', true);
->setContentType('text/css');
$cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css';
$cache = FileCache::instance();