/**
  * Prepare for sending
  *
  * @param RequestInterface $request Request to prepare
  * @throws \Exception on error preparing the request
  */
 protected function beforeSend(RequestInterface $request)
 {
     try {
         // Fix Content-Length and Transfer-Encoding collisions
         if ($request->hasHeader('Transfer-Encoding') && $request->hasHeader('Content-Length')) {
             $request->removeHeader('Transfer-Encoding');
         }
         $request->setState(RequestInterface::STATE_TRANSFER);
         $request->dispatch('request.before_send', array('request' => $request));
         if ($request->getState() != RequestInterface::STATE_TRANSFER) {
             // Requests might decide they don't need to be sent just before transfer (e.g. CachePlugin)
             $this->remove($request);
             if ($request->getState() == RequestInterface::STATE_COMPLETE) {
                 $this->successful[] = $request;
             }
         } else {
             // Add the request curl handle to the multi handle
             $this->checkCurlResult(curl_multi_add_handle($this->multiHandle, $this->createCurlHandle($request)->getHandle()));
         }
     } catch (\Exception $e) {
         // Queue the exception to be thrown when sent
         $this->removeErroredRequest($request, $e);
     }
 }
 /**
  * Prepare for sending
  *
  * @param RequestInterface $request Request to prepare
  */
 protected function beforeSend(RequestInterface $request)
 {
     try {
         $request->setState(RequestInterface::STATE_TRANSFER);
         $request->dispatch('request.before_send', array('request' => $request));
         if ($request->getState() != RequestInterface::STATE_TRANSFER) {
             // Requests might decide they don't need to be sent just before
             // transfer (e.g. CachePlugin)
             $this->remove($request);
         } else {
             if ($request->getParams()->get('queued_response')) {
                 // Queued responses do not need to be sent using curl
                 $this->remove($request);
                 $request->setState(RequestInterface::STATE_COMPLETE);
             } else {
                 // Add the request's curl handle to the multi handle
                 $this->checkCurlResult(curl_multi_add_handle($this->multiHandle, $this->createCurlHandle($request)->getHandle()));
             }
         }
     } catch (\Exception $e) {
         $this->removeErroredRequest($request, $e);
     }
 }