Parse response from cURL response. Sets body and headers.

@param $response
@param $curl

@return CurlResponse
336264
public function fromCurl ($response, $curl)
		{
			$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
			$this->_body = substr($response, $headerSize);

			$headers = substr($response, 0, $headerSize);
			$headers = str_replace("\r", "", $headers);
			$headers = str_replace("\n\n", "\n", $headers);
			$headers = trim($headers, "\n");
			$this->_headers = explode("\n", $headers);

			return $this;
		}
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }
22046
protected function parseCurlResponse($response)
    {
        $pattern = '|HTTP/\d\.\d.*?$.*?\r\n\r\n|ims';
        preg_match($pattern, $response, $matches);
        $header = $matches[0];
        // Remove headers from the response body
        $body = str_replace($header, '', $response);

        return [
            'header' => $header,
            'body' => $body
        ];
    }
106583
private function createResponse($content, $headers, \stdClass $curlMetaData) {
        $response = new Response();
        $response->setContent($content);
        $response->headers->add($headers);
        $response->setStatusCode($curlMetaData->http_code);

        return $response;
    }
539935
private function parseResponseBody(ResponseInterface $response)
    {
        $body = (string) $response->getBody();
        if (empty($body)) {
            if ($response->getStatusCode() === self::HTTP_NO_CONTENT) {
                return null;
            }

            throw new ApiException("No response body found.");
        }

        $object = @json_decode($body);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ApiException("Unable to decode Mollie response: '{$body}'.");
        }

        if ($response->getStatusCode() >= 400) {
            throw ApiException::createFromResponse($response);
        }

        return $object;
    }
200697
private function parseDiscoveryResponse($response)
    {
        $body = json_decode($response->getBody(), true);

        $this->authorization_endpoint = $body['authorization_endpoint'];
        $this->token_endpoint = $body['token_endpoint'];
        $this->end_session_endpoint = $body['end_session_endpoint'];
        $this->userinfo_endpoint = $body['userinfo_endpoint'];
        $this->jwks_uri = $body['jwks_uri'];

        $this->scopes_supported = $body['scopes_supported'];
    }
948232
public function dispatchResponse($response)
    {
        $parts = explode("\r\n\r\n", $response, 2);

        if (count($parts) < 2) {
            $this->throwException();
        }

        list($headersAsString, $body) = $parts;

        $headers = explode("\r\n", $headersAsString);
        list($code, $status) = $this->dispatchHttpStatus(array_shift($headers));
        $headers = $this->dispatchHeaders($headers);

        /** @var Emagedev_Utils_Model_Curl_Response $responseObject */
        $responseObject = Mage::getModel('emagedev_utils/curl_response');

        return $responseObject->setData(
            array(
                'code' => $code,
                'status' => $status,
                'headers_as_string' => $headersAsString,
                'headers' => $headers,
                'body' => $body
            )
        );
    }
549955
protected function responseWithHeaders($response)
    {
        foreach ($this->getHeaders() as $key => $value) {
            $response->headers->set($key, $value);
        }

        return $response;
    }
1333320
private function _buildResponse($response)
    {
        $sections = explode("\r\n\r\n", $response, 2);
        $body = isset($sections[1]) ? $sections[1] : NULL;
        $headers = array();
        $headerlines = explode("\n", $sections[0]);

        // process status
        list($http, $code, $message) = explode(' ', $headerlines[0], 3);

        // process headers
        foreach (array_slice($headerlines, 1) as $headerline) {
            $headers[] = HeaderField::fromString($headerline);
        }

        $response = new Response($code, $headers, $body);

        return $response;
    }
524250
private function getHttpResponse(&$header, &$response)
    {
        if (isset($header) && is_array($header) && (0 < count($header))) {
            $response = new HttpResponse($header);
            return true;
        }

        return false;
    }
670089
public static function parseResponse($response)
    {
        $response = is_array($response) ? $response : json_decode($response, true);

        if ( $response && $response['code'] == self::COSAPI_SUCCESS) {
            return $response;
        }

        return false;
    }
102304
protected function parseXML($response)
	{
		if ($response != '')
		{
			libxml_clear_errors();
			libxml_use_internal_errors(true);
			$xml = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA);
			if (libxml_get_errors())
			{
				$msg = var_export(libxml_get_errors(), true);
				libxml_clear_errors();
				throw new PrestaShopWebServiceException('HTTP XML response is not parsable: '.$msg);
			}
			return $xml;
		}
		else
			throw new PrestaShopWebServiceException('HTTP response is empty');
	}
1226673
private function parseHeader($curl, $headers)
    {
        if (!$this->responseStatusLine && strpos($headers, 'HTTP/') === 0) {
            $this->responseStatusLine = $headers;
        } else {
            $parts = explode(': ', $headers);
            if (isset($parts[1])) {
                $this->responseHeaders[$parts[0]] = trim($parts[1]);
            }
        }
        return strlen($headers);
    }
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;
    }
880174
private static function getHeaderAndBody($response) {
    $header = self::http_parse_headers(substr($response, 0, strrpos($response,"\r\n\r\n")));
    $body = substr($response, strrpos($response,"\r\n\r\n")+4);

    return array($header,$body);
  }
792638
protected static function handleResponse($response)
    {
        self::resolveContentType($response);

        $body = $response->getBody();
        $response = json_decode($body);

        self::resolveErrorResponse($response);

        return $response;
    }
713974
protected function curl() {
		$ch = curl_init($this->url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		$response = json_decode(curl_exec($ch));

		curl_close($ch);

		return $response;
	}