You are here

abstract class HttpClientDelegate in Http Client 6.2

Same name and namespace in other branches
  1. 7.2 includes/HttpClient.inc \HttpClientDelegate

Abstract base class for Http client delegates.

Hierarchy

Expanded class hierarchy of HttpClientDelegate

File

includes/HttpClient.inc, line 211

View source
abstract class HttpClientDelegate {

  /**
   * Executes a request for the HttpClient.
   *
   * @param HttpClient $client
   *  The client we're acting as a delegate for.
   * @param HttpClientRequest $request
   *  The request to execute.
   * @return object
   *  The interpreted response.
   */
  public abstract function execute(HttpClient $client, HttpClientRequest $request);

  /**
   * This function interprets a raw http response.
   *
   * @param HttpClient $client
   * @param string $response
   * @return object
   *  The interpreted response.
   */
  protected function interpretResponse(HttpClient $client, $response) {
    $client->rawResponse = $response;
    $split = preg_split('/\\r\\n\\r\\n/', $response, 2);
    if (!isset($split[1])) {
      throw new HttpClientException('Error interpreting response', 0, (object) array(
        'rawResponse' => $response,
      ));
    }
    list($headers, $body) = $split;
    $obj = (object) array(
      'headers' => $headers,
      'body' => $body,
    );

    // Drupal sends errors are via X-Drupal-Assertion-* headers,
    // generated by _drupal_log_error(). Read them to ease debugging.
    if (preg_match_all('/X-Drupal-Assertion-[0-9]+: (.*)\\n/', $headers, $matches)) {
      foreach ($matches[1] as $key => $match) {
        $obj->drupalErrors[] = print_r(unserialize(urldecode($match)), 1);
      }
    }
    $matches = array();
    if (preg_match('/HTTP\\/1.\\d (\\d{3}) (.*)/', $headers, $matches)) {
      $obj->responseCode = intVal(trim($matches[1]), 10);
      $obj->responseMessage = trim($matches[2]);

      // Handle HTTP/1.1 100 Continue
      if ($obj->responseCode == 100) {
        return $this
          ->interpretResponse($client, $body);
      }
    }
    return $obj;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpClientDelegate::execute abstract public function Executes a request for the HttpClient. 1
HttpClientDelegate::interpretResponse protected function This function interprets a raw http response.