Permalink
Browse files

Added context array to RequestInterface::setState() Removed curl.last…

…_options from request parameters Added CurlHandle to request.sent event CurlException now extends from RequestException rather than BadResponseException
  • Loading branch information...
1 parent abbab64 commit 55d8ca5d3d0de39405744129832c2b4f5a321e74 @mtdowling mtdowling committed Jan 13, 2013
View
@@ -208,7 +208,6 @@ public static function factory(RequestInterface $request)
// Apply the options to a new cURL handle.
$handle = curl_init();
curl_setopt_array($handle, $curlOptions);
- $request->getParams()->set('curl.last_options', $curlOptions);
if ($tempContentLength) {
$request->setHeader('Content-Length', $tempContentLength);
View
@@ -530,7 +530,7 @@ protected function processResponse(RequestInterface $request, CurlHandle $handle
$this->removeHandle($request);
if (!$curlException) {
- $request->setState(RequestInterface::STATE_COMPLETE);
+ $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);
@@ -7,7 +7,7 @@
/**
* cURL request exception
*/
-class CurlException extends BadResponseException
+class CurlException extends RequestException
{
private $curlError;
private $curlErrorNo;
@@ -61,9 +61,9 @@ public function __toString()
/**
* {@inheritdoc}
*/
- public function setState($state)
+ public function setState($state, array $context = array())
{
- parent::setState($state);
+ parent::setState($state, $context);
if ($state == self::STATE_TRANSFER && !$this->body && !count($this->postFields) && !count($this->postFiles)) {
$this->setHeader('Content-Length', 0)->removeHeader('Transfer-Encoding');
}
View
@@ -457,13 +457,13 @@ public function getState()
/**
* {@inheritdoc}
*/
- public function setState($state)
+ public function setState($state, array $context = array())
{
$this->state = $state;
if ($this->state == self::STATE_NEW) {
$this->response = null;
} elseif ($this->state == self::STATE_COMPLETE) {
- $this->processResponse();
+ $this->processResponse($context);
$this->responseBody = null;
}
@@ -725,9 +725,11 @@ protected function getEventArray()
/**
* Process a received response
*
+ * @param array $context Contextual information
+ *
* @throws BadResponseException on unsuccessful responses
*/
- protected function processResponse()
+ protected function processResponse(array $context = array())
{
// Use the queued response if one is set
if ($this->getParams()->get('queued_response')) {
@@ -744,7 +746,7 @@ protected function processResponse()
$this->state = self::STATE_COMPLETE;
// A request was sent, but we don't know if we'll send more or if the final response will be successful
- $this->dispatch('request.sent', $this->getEventArray());
+ $this->dispatch('request.sent', $this->getEventArray() + $context);
// Some response processors will remove the response or reset the state (example: ExponentialBackoffPlugin)
if ($this->state == RequestInterface::STATE_COMPLETE) {
@@ -233,11 +233,12 @@ public function getState();
/**
* Set the state of the request
*
- * @param string $state State of the request (complete, sending, or new)
+ * @param string $state State of the request (complete, sending, or new)
+ * @param array $context Contextual information about the state change
*
* @return RequestInterface
*/
- public function setState($state);
+ public function setState($state, array $context = array());
/**
* Get the cURL options that will be applied when the cURL handle is created

0 comments on commit 55d8ca5

Please sign in to comment.