public function Request::receiveResponseHeader

Method to receive HTTP response headers as they are retrieved

Parameters

string $data Header data.:

Return value

integer Returns the size of the data.

Overrides RequestInterface::receiveResponseHeader

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Message/Request.php, line 483

Class

Request
HTTP request class to send requests

Namespace

Guzzle\Http\Message

Code

public function receiveResponseHeader($data) {
  static $normalize = array(
    "\r",
    "\n",
  );
  $this->state = self::STATE_TRANSFER;
  $length = strlen($data);
  $data = str_replace($normalize, '', $data);
  if (strpos($data, 'HTTP/') === 0) {
    $startLine = explode(' ', $data, 3);
    $code = $startLine[1];
    $status = isset($startLine[2]) ? $startLine[2] : '';

    // Only download the body of the response to the specified response
    // body when a successful response is received.
    $body = $code >= 200 && $code < 300 ? $this
      ->getResponseBody() : EntityBody::factory();
    $this->response = new Response($code, null, $body);
    $this->response
      ->setStatus($code, $status)
      ->setRequest($this);
    $this
      ->dispatch('request.receive.status_line', array(
      'request' => $this,
      'line' => $data,
      'status_code' => $code,
      'reason_phrase' => $status,
    ));
  }
  elseif (strpos($data, ':') !== false) {
    list($header, $value) = explode(':', $data, 2);
    $this->response
      ->addHeader(trim($header), trim($value));
  }
  return $length;
}