@param $curlResponse
@param $curlInfo
@param $curlError

@return mixed
@throws \HpsException
518912
protected function processResponse($curlResponse, $curlInfo, $curlError)
    {
        // print "\n" . $curlResponse;
        $response = json_decode($curlResponse);

        switch ($curlInfo['http_code']) {
            case '200':
            case '204':
                return $response;
                break;
            case '400':
                throw new HpsException($response->error->message);
                break;
            default:
                throw new HpsException('Unexpected response');
                break;
        }
    }
1020222
public static function create($curlResponse, $headerSize) { 
        $headers = substr($curlResponse, 0, $headerSize);
        
        return function_exists('http_parse_headers') ? http_parse_headers($headers) : HTTPHeadersParser::parse($headers);
    }
732698
public function responseProcessor($response, $format, $curlError)
    {
        $format = (is_null($format)) ? $this->config->getFormat() : $format;
        switch ($format) {
            case 'json':
                return $response;
            case 'object':
                if ('NO_CURL_ERROR' == current($curlError)) {
                    return json_decode($response);
                } else {
                    $responseError = new \stdClass();
                    $responseError->error = $curlError;
                    return $responseError;
                }
                break;
            default:
                throw new BadParametersException(
                    sprintf('the "%s" format is not supported.', $format)
                );
        }
    }
581231
private function curlDelete($curl_url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $curl_url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($http_code != 200) {
            throw new Exception('curlDelete responded with '.$http_code.': '.$json_result->msg);
        }

        return true;
    }
707216
private function executeCurlRequest()
    {
        // Send the request and capture the response
        $rawResponse = $this->curl->sendRequest($this->options);

        // Fetch additional information about the request
        $responseInfo = $this->curl->getRequestInfo();

        if ( ! is_array($responseInfo))
        {
            throw new RequestException('Unable to retrieve request info array!');
        }

        // Get the error (if any)
        $errorCode = $this->curl->getErrorCode();
        $errorDescription = $this->curl->getErrorDescription();

        // Close Curl
        $this->curl->close();

        if ($errorCode > 0)
        {
            // There was a cURL error...
            throw new RequestException($errorDescription, $errorCode);
        }

        // Generate a response with the collected information
        return $this->responseFactory->make($rawResponse, $responseInfo);
    }
242798
protected function hydrateResponseFromCurl(Response $response, Curl $curl)
    {
        $headerSize = $curl->getInfo(CURLINFO_HEADER_SIZE);
        $rawContent = $this->multiCurl->getContent($curl);
        $response->setStatusCode($curl->getInfo(CURLINFO_HTTP_CODE))
                 ->setContent(substr($rawContent, $headerSize));
        $this->parseResponseHeaders($response, substr($rawContent, 0, $headerSize));
        return $this;
    }
599275
public static function curlValidate($curl)
    {
        if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE)) &&
            !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE])
        ) {
            throw new HttpException(self::$codes[$httpCode], $httpCode);
        }
    }
1065797
private function responseHeaderFunction($curlChannel, $headerData)
    {
        // we do NOT support multiple response headers with the same key, the
        // later one(s) will overwrite the earlier one
        if (false !== \strpos($headerData, ':')) {
            list($key, $value) = \explode(':', $headerData, 2);
            $this->responseHeaderList[\trim($key)] = \trim($value);
        }

        return Binary::safeStrlen($headerData);
    }
233301
public function streaming_write_callback($curl_handle, $data)
    {
        $code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
        
        if (intval($code) / 100 != 2)
        {
            $this->response_error_body .= $data;
            return strlen($data);
        }

        $length = strlen($data);
        $written_total = 0;
        $written_last = 0;
        
        while ($written_total < $length) {
            $written_last = fwrite($this->write_stream, substr($data, $written_total));

            if ($written_last === false) {
                return $written_total;
            }

            $written_total += $written_last;
        }

        // Execute callback function
        if ($this->registered_streaming_write_callback) {
            call_user_func($this->registered_streaming_write_callback, $curl_handle, $written_total);
        }

        return $written_total;
    }
556754
public function buildResponse($result) {
        if ($result === false) {
            if ($curlErrorNumber = curl_errno($this->_ch)) {
                $curlErrorString = curl_error($this->_ch);
                $this->_error($curlErrorString);

                $exception = new ConnectionErrorException('Unable to connect to "'.$this->uri.'": '
                        . $curlErrorNumber . ' ' . $curlErrorString);

                $exception->setCurlErrorNumber($curlErrorNumber)
                    ->setCurlErrorString($curlErrorString);

                throw $exception;
            }

            $this->_error('Unable to connect to "'.$this->uri.'".');
            throw new ConnectionErrorException('Unable to connect to "'.$this->uri.'".');
        }

        $info = curl_getinfo($this->_ch);

        // Remove the "HTTP/1.x 200 Connection established" string and any other headers added by proxy
        $proxy_regex = "/HTTP\/1\.[01] 200 Connection established.*?\r\n\r\n/si";
        if ($this->hasProxy() && preg_match($proxy_regex, $result)) {
            $result = preg_replace($proxy_regex, '', $result);
        }

        $response = explode("\r\n\r\n", $result, 2 + $info['redirect_count']);

        $body = array_pop($response);
        $headers = array_pop($response);

        return new Response($body, $headers, $this, $info);
    }
742591
public function resolve($curl, $response)
    {
        $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ( curl_errno($curl) ) {

            $this->fill(false, $http_status, curl_error($curl), []);

        } else {

            if ($http_status == 200) {

                $res = json_decode(EncryptAes::dencrypt($response));
                $this->fill($res->success, $http_status, curl_error($curl), $res);

            } else {

                $this->fill(false, $http_status, curl_error($curl), []);

            }

        }

        return $this;
    }
866441
public function getInfo($key)
    {
        if (!array_key_exists($key, $this->infos)) {
            throw new CurlException('Information ' . $key . ' not found in CurlRequest');
        }

        return $this->infos[$key];
    }
463478
public function logRequest($curlInfo, $params) {
    $paramsString = '';
    $curlInfoString = '';

    foreach ($params as $k => $v) {
      $paramsString .= "$k=$v\r\n";
    }

    foreach ($curlInfo as $k => $v) {
      if (!is_array($v)) {
        $curlInfoString .= "$k=$v\r\n";
      }
      else {
        $curlInfoString .= "$k {\r\n";

        foreach ($v as $k2 => $v2) {
          $curlInfoString .= "$k2=$v2\r\n";
        }

        $curlInfoString .= "}\r\n";
      }
    }

    $this->writeLog(sprintf($this->debugStrings['curlRequest'], date('Y-m-d H:i:s'), $paramsString, $curlInfoString));
  }
860372
public function processResponse($curlResponse, $curlInfo, $curlError)
    {
        // error_log($curlResponse);
        switch ($curlInfo['http_code']) {
            case '200':
                return simplexml_load_string($curlResponse);
                break;
            case '500':
                $faultString = '';
                throw new HpsException($faultString);
                break;
            default:
                throw new HpsException('Unexpected response');
                break;
        }
    }
1135035
public function execute() {
        $value = curl_exec($this->handle);

        $error_no = curl_errno($this->handle);

        if (0 !== $error_no) {
            throw new CurlErrorException(curl_error($this->handle), $error_no);
        }

        return $value;
    }
1264006
private function executeCurlResource() {
        $this->returnedTransfer = curl_exec($this->curlResource);
        if (false === $this->returnedTransfer) {
            $message = sprintf("CURL ERROR #%s: %s", $this->getCurlErrorNumber(), $this->getCurlError());
            throw new ResponseException($message);
        }
        $this->info = (object)curl_getinfo($this->curlResource);
    }
1365763
public function call($method, $url, array $post = array(), array $headers = array())
    {
        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPHEADER => $headers,
        );
        switch ($method) {
            case HttpMethod::GET:
                $options[CURLOPT_POST] = false;
                break;
            case HttpMethod::POST:
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            case HttpMethod::PUT:
                $options[CURLOPT_CUSTOMREQUEST] = 'PUT';
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            case HttpMethod::DELETE:
                $options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            default:
                throw new InvalidArgumentException(sprintf('Invalid method: %s', $method));
        }

        $this->curl->init();
        $this->curl->setOptArray($options);
        $rawResponse = $this->curl->exec(1, true);
        $contentType = $this->curl->getInfo(CURLINFO_CONTENT_TYPE);
        if (strpos($contentType, self::CONTENT_TYPE_JSON) === false) {
            return $rawResponse;
        }
        $response = json_decode($rawResponse);
        if (!isset($response->response)) {
            throw new RuntimeException(sprintf('Unexpected response: %s', $rawResponse));
        }
        $response = $response->response;
        if ('OK' == @$response->status) {
            return $response;
        } elseif ('NOAUTH' == @$response->error_id || 'Authentication failed - not logged in' == @$response->error) {
            throw new TokenExpiredException($response);
        }
        throw new ServerException($response);
    }