function handleRequest(RequestInterface $request) { $this->request = $request; $response = new Response(array('headers' => array('Content-Type' => $this->getConfig('default_content_type'), 'Content-Language' => $this->getConfig('default_language')))); try { if (!$this->qualify($this->getPathComponents())) { throw new NotFound(); } $response->setContent($this->runIfExists($request->getMethod())); } catch (NotFound $e) { $response->setStatus(404); } catch (MethodUndefined $e) { $response->setStatus(405); $response->setHeader('Allow', $this->getDefinedMethods()); } catch (Redirect $e) { $payload = $e->getPayload(); $response->setStatus($payload['status_code']); $response->setHeader('Location', $payload['location']); if (isset($payload['locations_list'])) { $response->setHeader('Asar-Internal-Locationslist', $payload['locations_list']); } } catch (ForwardRequest $e) { throw $e; } catch (\Exception $e) { $response->setStatus(500); $response->setContent($e->getMessage()); } return $response; }