From 0ef81a2e0b50fb55248c350be6479b4d40f3e833 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 9 Nov 2016 11:38:04 +0100 Subject: [PATCH] Response: Use a constant for the default content type There is already setHeader() to adjust this dynamically. refs #12161 --- library/Icinga/Web/Response.php | 39 ++++---------------- library/Icinga/Web/Response/JsonResponse.php | 12 +++--- library/Icinga/Web/StyleSheet.php | 2 +- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php index a42f48fde..d58ca4e1a 100644 --- a/library/Icinga/Web/Response.php +++ b/library/Icinga/Web/Response.php @@ -12,6 +12,13 @@ use Icinga\Web\Response\JsonResponse; */ 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 * @@ -54,13 +61,6 @@ 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 * @@ -237,29 +237,6 @@ 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 * @@ -301,7 +278,7 @@ class Response extends Zend_Controller_Response_Http } if (! $this->getHeader('Content-Type', true)) { - $this->setHeader('Content-Type', $this->getContentType()); + $this->setHeader('Content-Type', static::DEFAULT_CONTENT_TYPE); } } diff --git a/library/Icinga/Web/Response/JsonResponse.php b/library/Icinga/Web/Response/JsonResponse.php index 47a2ccd74..744456c82 100644 --- a/library/Icinga/Web/Response/JsonResponse.php +++ b/library/Icinga/Web/Response/JsonResponse.php @@ -11,6 +11,11 @@ use Icinga\Web\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 * @@ -67,13 +72,6 @@ class JsonResponse extends Response */ protected $successData; - /** - * Content type of this response - * - * @var string - */ - protected $contentType = 'application/json'; - /** * Get the JSON encoding options * diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index e74f3c955..549e11c5c 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -197,7 +197,7 @@ class StyleSheet $response ->setHeader('Cache-Control', 'public', true) ->setHeader('ETag', $etag, true) - ->setContentType('text/css'); + ->setHeader('Content-Type', 'text/css', true); $cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css'; $cache = FileCache::instance();