You are here

function HttpClientCurlDelegate::execute in Http Client 6.2

Same name and namespace in other branches
  1. 7.2 includes/HttpClientCurlDelegate.inc \HttpClientCurlDelegate::execute()

Executes a request for the HttpClient.

Parameters

HttpClient $client: The client we're acting as a delegate for.

HttpClientRequest $request: The request to execute.

Return value

object The interpreted response.

Overrides HttpClientDelegate::execute

File

includes/HttpClientCurlDelegate.inc, line 17

Class

HttpClientCurlDelegate
A delegate for the HttpClient that uses curl to fetch data.

Code

function execute(HttpClient $client, HttpClientRequest $request) {
  $curlopts = array();
  if (isset($client->options['curlopts'])) {
    $curlopts = $curlopts + $client->options['curlopts'];
  }
  if (isset($request->options['curlopts'])) {
    $curlopts = $request->options['curlopts'] + $curlopts;
  }
  $ch = $this
    ->curl($request, $curlopts);
  $response = curl_exec($ch);
  $error = curl_error($ch);
  curl_close($ch);
  if ($error) {
    throw new HttpClientException('Curl Error: ' . $error);
  }
  return $this
    ->interpretResponse($client, $response);
}