You are here

protected function Client::doRequest in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/http-kernel/Client.php \Symfony\Component\HttpKernel\Client::doRequest()
  2. 8.0 vendor/symfony/browser-kit/Client.php \Symfony\Component\BrowserKit\Client::doRequest()
  3. 8.0 vendor/fabpot/goutte/Goutte/Client.php \Goutte\Client::doRequest()
Same name and namespace in other branches
  1. 8 vendor/fabpot/goutte/Goutte/Client.php \Goutte\Client::doRequest()

Parameters

Request $request:

Return value

Response

Overrides Client::doRequest

File

vendor/fabpot/goutte/Goutte/Client.php, line 84

Class

Client
Client.

Namespace

Goutte

Code

protected function doRequest($request) {
  $headers = array();
  foreach ($request
    ->getServer() as $key => $val) {
    $key = strtolower(str_replace('_', '-', $key));
    $contentHeaders = array(
      'content-length' => true,
      'content-md5' => true,
      'content-type' => true,
    );
    if (0 === strpos($key, 'http-')) {
      $headers[substr($key, 5)] = $val;
    }
    elseif (isset($contentHeaders[$key])) {
      $headers[$key] = $val;
    }
  }
  $cookies = CookieJar::fromArray($this
    ->getCookieJar()
    ->allRawValues($request
    ->getUri()), parse_url($request
    ->getUri(), PHP_URL_HOST));
  $requestOptions = array(
    'cookies' => $cookies,
    'allow_redirects' => false,
    'auth' => $this->auth,
  );
  if (!in_array($request
    ->getMethod(), array(
    'GET',
    'HEAD',
  ))) {
    if (null !== ($content = $request
      ->getContent())) {
      $requestOptions['body'] = $content;
    }
    else {
      if ($files = $request
        ->getFiles()) {
        $requestOptions['multipart'] = [];
        $this
          ->addPostFields($request
          ->getParameters(), $requestOptions['multipart']);
        $this
          ->addPostFiles($files, $requestOptions['multipart']);
      }
      else {
        $requestOptions['form_params'] = $request
          ->getParameters();
      }
    }
  }
  if (!empty($headers)) {
    $requestOptions['headers'] = $headers;
  }
  $method = $request
    ->getMethod();
  $uri = $request
    ->getUri();
  foreach ($this->headers as $name => $value) {
    $requestOptions['headers'][$name] = $value;
  }

  // Let BrowserKit handle redirects
  try {
    $response = $this
      ->getClient()
      ->request($method, $uri, $requestOptions);
  } catch (RequestException $e) {
    $response = $e
      ->getResponse();
    if (null === $response) {
      throw $e;
    }
  }
  return $this
    ->createResponse($response);
}