From 7cef06f981d41d329477c0d19cdd32bd74477b0b Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sat, 27 Feb 2016 20:14:02 +0100 Subject: [PATCH] Disable benchmark only if the layout is disabled Benchmark should be disabled if the response is not HTML. This is most likely the case when the layout is disabled. If Web 2 or Zend sends JSON for example, the layout is disabled. The follwing code inside an action disables the layout (and view): $this->_helper->layout()->disableLayout(); The following code inside an action disables the action's view script: $this->_helper->viewRenderer->setNoRender(true); Note that an action's view script is also disabled via setNoRender() when rendering another view script via render() or renderScript(). Another appraoch is to check the content-type. If explicitly set to not HTML, disable benchmark: $renderBenchmark = true; $response = $this->getResponse(); $headers = $response->getHeaders(); foreach ($headers as $header) { if (strtolower($header['name']) === 'content-type' && stristr($header['value'], 'text/html') === false ) { $renderBenchmark = false; break; } } if ($renderBenchmark) { $layout->benchmark = $this->renderBenchmark(); } Maybe we should also provide a action method for disabling benchmark, regardless of the user's setting. refs #10856 --- library/Icinga/Web/Controller/ActionController.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index c4a4d8344..0703e4e98 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -459,15 +459,13 @@ class ActionController extends Zend_Controller_Action $layout->innerLayout = $this->innerLayout; if ($user = $req->getUser()) { - // Cast preference app.show_benchmark to bool because preferences loaded from a preferences storage are - // always strings - if ((bool) $user->getPreferences()->getValue('icingaweb', 'show_benchmark', false) === true) { - if (!$this->_helper->viewRenderer->getNoRender()) { + if ((bool) $user->getPreferences()->getValue('icingaweb', 'show_benchmark', false)) { + if ($this->_helper->layout()->isEnabled()) { $layout->benchmark = $this->renderBenchmark(); } } - if ((bool) $user->getPreferences()->getValue('icingaweb', 'auto_refresh', true) === false) { + if (! (bool) $user->getPreferences()->getValue('icingaweb', 'auto_refresh', true)) { $this->disableAutoRefresh(); } }