mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 10:33:18 +01:00
Using a small clone of a request when setting on a response to avoid a circular reference
This commit is contained in:
parent
aae077a12b
commit
db1d7ae3aa
@ -500,7 +500,8 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
$body = $code >= 200 && $code < 300 ? $this->getResponseBody() : EntityBody::factory();
|
||||
|
||||
$this->response = new Response($code, null, $body);
|
||||
$this->response->setStatus($code, $status)->setRequest($this);
|
||||
$this->response->setStatus($code, $status);
|
||||
$this->setRequestOnResponse($this->response);
|
||||
$this->dispatch('request.receive.status_line', array(
|
||||
'request' => $this,
|
||||
'line' => $data,
|
||||
@ -524,7 +525,7 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
{
|
||||
// Never overwrite the request associated with the response (useful for redirect history)
|
||||
if (!$response->getRequest()) {
|
||||
$response->setRequest($this);
|
||||
$this->setRequestOnResponse($response);
|
||||
}
|
||||
|
||||
if ($queued) {
|
||||
@ -789,4 +790,18 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a request closure on a response
|
||||
*
|
||||
* @param Response $response
|
||||
* @deprecated
|
||||
*/
|
||||
protected function setRequestOnResponse(Response $response)
|
||||
{
|
||||
$headers = $this->getRawHeaders();
|
||||
$response->setRequest(function () use ($headers) {
|
||||
return RequestFactory::getInstance()->fromMessage($headers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class Response extends AbstractMessage
|
||||
protected $info = array();
|
||||
|
||||
/**
|
||||
* @var RequestInterface Request object that may or may not be set
|
||||
* @var RequestInterface|callable Request object that may or may not be set
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
@ -343,16 +343,6 @@ class Response extends AbstractMessage
|
||||
return $headers . "\r\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request object (or null) that is associated with this response
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response reason phrase- a human readable version of the numeric
|
||||
* status code
|
||||
@ -779,17 +769,33 @@ class Response extends AbstractMessage
|
||||
/**
|
||||
* Set the request object associated with the response
|
||||
*
|
||||
* @param RequestInterface $request The request object used to generate the response
|
||||
* @param mixed $request The request object used to generate the response or a closure to return a request
|
||||
*
|
||||
* @return Response
|
||||
* @deprecated
|
||||
*/
|
||||
public function setRequest(RequestInterface $request)
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request object (or null) that is associated with this response
|
||||
*
|
||||
* @return RequestInterface
|
||||
* @deprecated
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
if (is_callable($this->request)) {
|
||||
$this->request = call_user_func($this->request);
|
||||
}
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the response can be cached
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user