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; }
function testExportResponseHeadersUsesHeaderFunctionWrapper() { $exporter = $this->getMock('Asar\\ResponseExporter', array('header')); $exporter->expects($this->exactly(3))->method('header'); $exporter->expects($this->at(0))->method('header')->with($this->equalTo('Content-Type: text/plain')); $exporter->expects($this->at(1))->method('header')->with($this->equalTo('Content-Encoding: gzip')); $exporter->expects($this->at(2))->method('header')->with($this->equalTo('HTTP/1.1 404 Not Found')); $response = new Response(); $response->setHeader('Content-Type', 'text/plain'); $response->setHeader('Content-Encoding', 'gzip'); $response->setStatus(404); $exporter->exportResponse($response); }