Check for errors and fix headers of a request based on a curl response
RequestInterface $request Request to process:
CurlHandle $handle Curl handle object:
array $curl Array returned from curl_multi_info_read:
CurlException on Curl error
protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl) {
// Set the transfer stats on the response
$handle
->updateRequestFromTransfer($request);
// Check if a cURL exception occurred, and if so, notify things
$curlException = $this
->isCurlException($request, $handle, $curl);
// Always remove completed curl handles. They can be added back again
// via events if needed (e.g. ExponentialBackoffPlugin)
$this
->removeHandle($request);
if (!$curlException) {
$request
->setState(RequestInterface::STATE_COMPLETE, array(
'handle' => $handle,
));
// Only remove the request if it wasn't resent as a result of the state change
if ($request
->getState() != RequestInterface::STATE_TRANSFER) {
$this
->remove($request);
}
}
else {
// Set the state of the request to an error
$request
->setState(RequestInterface::STATE_ERROR);
// Notify things that listen to the request of the failure
$request
->dispatch('request.exception', array(
'request' => $this,
'exception' => $curlException,
));
// Allow things to ignore the error if possible
$state = $request
->getState();
if ($state != RequestInterface::STATE_TRANSFER) {
$this
->remove($request);
}
// The error was not handled, so fail
if ($state == RequestInterface::STATE_ERROR) {
/** @var $curlException \Exception */
throw $curlException;
}
}
}