function authcache_p13n_frontcontroller_handle_request in Authenticated User Page Caching (Authcache) 7.2
Dispatch incomming requests to the appropriate request handler.
Parameters
array $req: The request parameters as extracted by authcache_p13n_frontcontroller_prepare_request
See also
authcache_p13n_frontcontroller_prepare_request()
2 calls to authcache_p13n_frontcontroller_handle_request()
- authcache.php in modules/
authcache_p13n/ safe_frontcontroller/ authcache.php - Alternative front controller for user specific content fragments.
- authcache.php in modules/
authcache_p13n/ frontcontroller/ authcache.php - Default front controller for user specific content fragments.
File
- modules/
authcache_p13n/ includes/ frontcontroller.inc, line 49 - Defines the main function for the front controller.
Code
function authcache_p13n_frontcontroller_handle_request($req) {
// Front controller configuration.
$check_header = variable_get('authcache_p13n_checkheader', TRUE);
$routerclass = variable_get('authcache_p13n_router', 'AuthcacheP13nDefaultRequestRouter');
ob_start();
try {
// This frontcontroller is only capable of responding to GET and HEAD
// requests.
if (!($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'HEAD')) {
drupal_add_http_header('Allow', 'GET, HEAD');
throw new AuthcacheP13nRequestException('405 Method Not Allowed');
}
// Check whether the authcache HTTP header is present on the request.
if ($check_header && empty($_SERVER['HTTP_X_AUTHCACHE'])) {
watchdog('Authcache P13n Front Controller', 'X-Authcache header is missing on request', array(), WATCHDOG_ERROR);
throw new AuthcacheP13nRequestInvalidInput();
}
// Check whether the client supplied a request-id.
if (empty($req['r'])) {
watchdog('Authcache P13n Front Controller', 'Missing r-parameter on request', array(), WATCHDOG_ERROR);
throw new AuthcacheP13nRequestInvalidInput();
}
// Resolve and instantiate request handler.
$router = new $routerclass();
$handler = $router
->getHandler($req['r']);
unset($req['r']);
if ($handler === FALSE) {
throw new AuthcacheP13nRequestInvalidInput();
}
// Send response.
$handler
->handle($req);
if ($_SERVER['REQUEST_METHOD'] === 'HEAD') {
// Discard output if client does not care about it.
ob_end_clean();
}
else {
ob_end_flush();
}
} catch (Exception $e) {
if (is_a($e, 'AuthcacheP13nRequestException')) {
$status = $e
->getMessage();
}
else {
$status = '500 Internal Server Error';
watchdog_exception('Authcache P13n Front Controller', $e);
}
drupal_add_http_header('Status', $status);
// Discard output.
ob_end_clean();
}
}