icingaweb2/library/Icinga/Web/Controller
Eric Lippmann 7cef06f981 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
2016-02-27 20:14:02 +01:00
..
ActionController.php Disable benchmark only if the layout is disabled 2016-02-27 20:14:02 +01:00
AuthBackendController.php Change all license headers to only reflect a file's year of creation 2016-02-08 15:41:00 +01:00
BasePreferenceController.php Change all license headers to only reflect a file's year of creation 2016-02-08 15:41:00 +01:00
ControllerTabCollector.php Change all license headers to only reflect a file's year of creation 2016-02-08 15:41:00 +01:00
Dispatcher.php Change all license headers to only reflect a file's year of creation 2016-02-08 15:41:00 +01:00
ModuleActionController.php Change all license headers to only reflect a file's year of creation 2016-02-08 15:41:00 +01:00