public function Request::setResponse

Manually set a response for the request.

This method is useful for specifying a mock response for the request or setting the response using a cache. Manually setting a response will bypass the actual sending of a request.

Parameters

Response $response Response object to set:

bool $queued Set to TRUE to keep the request in a state of not having been sent, but queue the: response for send()

Return value

RequestInterface Returns a reference to the object.

Overrides RequestInterface::setResponse

File

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

Class

Request
HTTP request class to send requests

Namespace

Guzzle\Http\Message

Code

public function setResponse(Response $response, $queued = false) {

  // Never overwrite the request associated with the response (useful for redirect history)
  if (!$response
    ->getRequest()) {
    $response
      ->setRequest($this);
  }
  if ($queued) {
    $this
      ->getParams()
      ->set('queued_response', $response);
  }
  else {
    $this
      ->getParams()
      ->remove('queued_response');
    $this->response = $response;
    $this->responseBody = $response
      ->getBody();
    $this
      ->processResponse();
  }
  $this
    ->dispatch('request.set_response', $this
    ->getEventArray());
  return $this;
}