Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions library/Icinga/Application/Hook/RequestHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Icinga\Application\Hook;

use Icinga\Application\Hook;
use Icinga\Application\Logger;
use Icinga\Web\Request;
use Throwable;

abstract class RequestHook extends Hook
{
/**
* Triggered after a request has been dispatched
*
* @param Request $request
*
* @return void
*/
abstract public function onPostDispatch(Request $request): void;

/**
* Call the onPostDispatch() method of all registered RequestHooks
*
* @param Request $request
*
* @return void
*/
final public static function postDispatch(Request $request): void
{
foreach (static::all('Request') as $hook) {
try {
$hook->onPostDispatch($request);
} catch (Throwable $e) {
Logger::error('Failed to execute hook on request: %s', $e);
}
}
}
}
23 changes: 13 additions & 10 deletions library/Icinga/Web/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@

namespace Icinga\Web\Controller;

use Icinga\Application\Modules\Module;
use Icinga\Common\PdfExport;
use Icinga\File\Pdf;
use Icinga\Util\Csp;
use Icinga\Web\View;
use ipl\I18n\Translation;
use Zend_Controller_Action;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Request_Abstract;
use Zend_Controller_Response_Abstract;
use Icinga\Application\Benchmark;
use Icinga\Application\Config;
use Icinga\Application\Hook\RequestHook;
use Icinga\Application\Modules\Module;
use Icinga\Authentication\Auth;
use Icinga\Common\PdfExport;
use Icinga\Exception\Http\HttpMethodNotAllowedException;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
use Icinga\File\Pdf;
use Icinga\Forms\AutoRefreshForm;
use Icinga\Security\SecurityException;
use Icinga\Util\Csp;
use Icinga\Web\Session;
use Icinga\Web\Url;
use Icinga\Web\UrlParams;
use Icinga\Web\View;
use Icinga\Web\Widget\Tabs;
use Icinga\Web\Window;
use ipl\I18n\Translation;
use Zend_Controller_Action;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Request_Abstract;
use Zend_Controller_Response_Abstract;

/**
* Base class for all core action controllers
Expand Down Expand Up @@ -520,6 +521,8 @@ public function postDispatch()

if ($this->isXhr()) {
$this->postDispatchXhr();
} else {
RequestHook::postDispatch($req);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think letting the hook decide would be clever AND smart. I mean, anyone could provide a hook... and wonder why some requests are missing. If $this->isXhr() is too heavy just with $req, we can pass additional arguments like a bool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already discussed this w/ @jrauh01. We will call postDispatch() unconditionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrauh01 Please also add the following to our Request:

public function isAutoRefresh(): bool
{
    return $this->getHeader('X-Icinga-Autorefresh');
}

}

$this->shutdownSession();
Expand Down
Loading