/** * Sends request to the remote server and returns its response * * @param Diglin_HTTP_Request2 * @return Diglin_HTTP_Request2_Response * @throws Diglin_HTTP_Request2_Exception */ public function sendRequest(Diglin_HTTP_Request2 $request) { if (!extension_loaded('curl')) { throw new Diglin_HTTP_Request2_Exception('cURL extension not available'); } $this->request = $request; $this->response = null; $this->position = 0; $this->eventSentHeaders = false; $this->eventReceivedHeaders = false; try { if (false === curl_exec($ch = $this->createCurlHandle())) { $errorMessage = 'Error sending request: #' . curl_errno($ch) . ' ' . curl_error($ch); } } catch (Exception $e) { } $this->lastInfo = curl_getinfo($ch); curl_close($ch); $response = $this->response; unset($this->request, $this->requestBody, $this->response); if (!empty($e)) { throw $e; } elseif (!empty($errorMessage)) { throw new Diglin_HTTP_Request2_Exception($errorMessage); } if (0 < $this->lastInfo['size_download']) { $request->setLastEvent('receivedBody', $response); } return $response; }