/** * @param string $method * @param string $path * @param array $headers * @param string|null $body * @return Http\Response */ protected function getHttpResponse($method, $path, array $headers = [], $body = NULL) { $sl = $this->getContainer(); $processor = new Api\RequestProcessor($sl, $logger = new Api\HttpLogger(), $this->baseUrl); $processor->setRouter($this->router); try { $processor->request($method, $path, $headers, $body); } finally { $this->appResponse = $processor->getAppResponse(); $classRefl = new \ReflectionClass($this); $logger->write(dirname($classRefl->getFileName()) . '/requests.log'); } return $processor->getHttpResponse(); }
/** * @param string $method * @param string $path * @param array $headers * @param string|null $body * @return Http\Response */ public function request($method, $path, array $headers = [], $body = NULL) { $this->appResponse = NULL; $url = new Http\UrlScript($this->baseUri . $path); $this->httpRequest = (new HttpRequestMock($url, NULL, [], [], [], $headers, $method, '127.0.0.1', '127.0.0.1'))->setRawBody($body); $this->httpResponse = new HttpResponseMock(); // mock request & response $this->sl->removeService('httpRequest'); $this->sl->addService('httpRequest', $this->httpRequest); $this->sl->removeService('httpResponse'); $this->sl->addService('httpResponse', $this->httpResponse); /** @var Kdyby\FakeSession\Session $session */ $session = $this->sl->getService('session'); $session->__construct(new Http\Session($this->httpRequest, $this->httpResponse)); /** @var Nette\Application\IPresenterFactory $presenterFactory */ $presenterFactory = $this->sl->getByType('Nette\\Application\\IPresenterFactory'); /** @var Application $application */ $application = $this->sl->getByType('Nette\\Application\\Application'); $application->__construct($presenterFactory, $this->getRouter(), $this->httpRequest, $this->httpResponse); $application->onResponse[] = function (Application $application, Nette\Application\IResponse $response) { $this->appResponse = $response; $this->httpResponse->setAppResponse($response); }; $appRequest = $this->getRouter()->match($this->httpRequest); $this->onBeforeRequest($appRequest, $this->sl); try { ob_start(); try { $this->appResponse = NULL; $application->processRequest($appRequest); } catch (\Exception $e) { $application->processException($e); } $this->httpResponse->setContent(ob_get_clean()); } finally { $this->logger->log($this->httpRequest, $this->httpResponse); } return $this->httpResponse; }
public function formatHeaders(array $headers) { unset($headers['Content-Type'], $headers['Vary'], $headers['Cache-Control'], $headers['Expires']); return parent::formatHeaders($headers); }