Response: Use a constant for the default content type

There is already setHeader() to adjust this dynamically.

refs #12161
This commit is contained in:
Johannes Meyer 2016-11-09 11:38:04 +01:00
parent 93474972bf
commit 0ef81a2e0b
3 changed files with 14 additions and 39 deletions

View File

@ -12,6 +12,13 @@ use Icinga\Web\Response\JsonResponse;
*/ */
class Response extends Zend_Controller_Response_Http class Response extends Zend_Controller_Response_Http
{ {
/**
* The default content type being used for responses
*
* @var string
*/
const DEFAULT_CONTENT_TYPE = 'text/html';
/** /**
* Auto-refresh interval * Auto-refresh interval
* *
@ -54,13 +61,6 @@ class Response extends Zend_Controller_Response_Http
*/ */
protected $rerenderLayout = false; protected $rerenderLayout = false;
/**
* Content type of this response
*
* @var string
*/
protected $contentType = 'text/html';
/** /**
* Get the auto-refresh interval * Get the auto-refresh interval
* *
@ -237,29 +237,6 @@ class Response extends Zend_Controller_Response_Http
return $this; 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 * Entry point for HTTP responses in JSON format
* *
@ -301,7 +278,7 @@ class Response extends Zend_Controller_Response_Http
} }
if (! $this->getHeader('Content-Type', true)) { if (! $this->getHeader('Content-Type', true)) {
$this->setHeader('Content-Type', $this->getContentType()); $this->setHeader('Content-Type', static::DEFAULT_CONTENT_TYPE);
} }
} }

View File

@ -11,6 +11,11 @@ use Icinga\Web\Response;
*/ */
class JsonResponse extends Response class JsonResponse extends Response
{ {
/**
* {@inheritdoc}
*/
const DEFAULT_CONTENT_TYPE = 'application/json';
/** /**
* Status identifier for failed API calls due to an error on the server * Status identifier for failed API calls due to an error on the server
* *
@ -67,13 +72,6 @@ class JsonResponse extends Response
*/ */
protected $successData; protected $successData;
/**
* Content type of this response
*
* @var string
*/
protected $contentType = 'application/json';
/** /**
* Get the JSON encoding options * Get the JSON encoding options
* *

View File

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