public function testCurlException() { $request = HttpRequest::create()->setUrl(HttpUrl::create()->parse('http://nonexistentdomain.xyz'))->setMethod(HttpMethod::get()); try { $response = CurlHttpClient::create()->setTimeout(3)->send($request); $this->fail(); } catch (NetworkException $e) { $this->assertContains('curl error', $e->getMessage()); } }
/** * @param string $url * @return HttpRequest **/ protected function buildRequest($url) { ServerVarUtils::build($_SERVER, $url); return HttpRequest::create()->setServer($_SERVER); }
<?php /** * $Id$ **/ define('PATH_SOURCE_DIR', 'admin' . DIRECTORY_SEPARATOR); require '../../../config.inc.php'; try { $request = HttpRequest::create()->setGet($_GET)->setPost($_POST)->setCookie($_COOKIE)->setServer($_SERVER)->setSession($_SESSION)->setFiles($_FILES); $controllerName = 'main'; if (isset($_GET['area']) && is_readable(PATH_CONTROLLERS . $_GET['area'] . EXT_CLASS)) { $controllerName = $_GET['area']; } $controller = new AuthorizationFilter(new $controllerName()); $modelAndView = $controller->handleRequest($request); $view = $modelAndView->getView(); $model = $modelAndView->getModel(); $prefix = PATH_WEB_ADMIN . '?area='; if (!$view) { $view = $controllerName; } elseif (is_string($view) && $view == 'error') { $view = new RedirectView($prefix); } elseif ($view instanceof RedirectToView) { $view->setPrefix($prefix); } if (!$view instanceof View) { $viewName = $view; $view = PhpViewResolver::create(PATH_TEMPLATES, EXT_TPL)->resolveViewName($viewName); } if (!$view instanceof RedirectView) { $model->set('selfUrl', $_SERVER['PHP_SELF'] . '?area=' . $controllerName)->set('baseUrl', $_SERVER['PHP_SELF']);
protected function loadXRDS($url) { $response = $this->httpClient->send(HttpRequest::create()->setHeaderVar('Accept', self::HEADER_ACCEPT)->setMethod(HttpMethod::get())->setUrl(HttpUrl::create()->parse($url))); if ($response->getStatus()->getId() != 200) { throw new OpenIdException('can\'t fetch document'); } $this->parseXRDS($response->getBody()); return $this; }
/** * @param string $host * @return HttpRequest **/ protected function buildRequest($host, $schema = 'http') { ServerVarUtils::build($_SERVER, $schema . '://' . $host); return HttpRequest::create()->setServer($_SERVER); }
/** * check_authentication mode request **/ private function checkAuthentication(array $parameters, $manager = null) { $credentials = new OpenIdCredentials(HttpUrl::create()->parse($parameters['openid.identity']), $this->httpClient); $request = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl($credentials->getServer()); if (isset($parameters['openid.invalidate_handle']) && $manager) { $request->setPostVar('openid.invalidate_handle', $parameters['openid.invalidate_handle']); } foreach (explode(',', $parameters['openid.signed']) as $key) { $key = 'openid.' . $key; $request->setPostVar($key, $parameters[$key]); } $request->setPostVar('openid.mode', 'check_authentication')->setPostVar('openid.assoc_handle', $parameters['openid.assoc_handle'])->setPostVar('openid.sig', $parameters['openid.sig'])->setPostVar('openid.signed', $parameters['openid.signed']); $response = $this->httpClient->send($request); if ($response->getStatus()->getId() != HttpStatus::CODE_200) { throw new OpenIdException('bad response code from server'); } $result = $this->parseKeyValueFormat($response->getBody()); if (!isset($result['is_valid']) || $result['is_valid'] !== 'true' && $result['is_valid'] !== 'false') { throw new OpenIdException('strange response given'); } if ($result['is_valid'] === 'true') { if (isset($result['invalidate_handle']) && $manager) { $manager->purgeByHandle($result['invalidate_handle']); } return true; } elseif ($result['is_valid'] === 'false') { return false; } Assert::isUnreachable(); }
protected function buildIncorrectRequest() { return HttpRequest::create(); }
/** * @param HttpMethod $method * @return HttpRequest */ private function spawnRequest(HttpMethod $method, $urlPostfix = '') { $url = HttpUrl::create()->parse(ONPHP_CURL_TEST_URL); $glue = $url->getQuery() ? '&' : '?'; return HttpRequest::create()->setUrl($url->parse(ONPHP_CURL_TEST_URL . $glue . $urlPostfix))->setMethod($method); }