{
$ch = curl_init();
$options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
$options[CURLOPT_NOBODY] = ($method ===
'HEAD');
$options[CURLOPT_CAINFO] = $this->options->get(
'curl.certpath', __DIR__ .
'/cacert.pem');
if (isset($data))
{
if (is_scalar($data) || (isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'multipart/form-data') === 0))
{
}
else
{
$options[CURLOPT_POSTFIELDS] = http_build_query($data);
}
if (!isset($headers['Content-Type']))
{
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
if (is_scalar(
$options[CURLOPT_POSTFIELDS]))
{
$headers[
'Content-Length'] = strlen(
$options[CURLOPT_POSTFIELDS]);
}
}
$headerArray = array();
if (isset($headers))
{
foreach ($headers as $key => $value)
{
$headerArray[] = $key . ': ' . $value;
}
$options[CURLOPT_HTTPHEADER] = $headerArray;
}
if (isset($timeout))
{
$options[CURLOPT_TIMEOUT] = (int) $timeout;
$options[CURLOPT_CONNECTTIMEOUT] = (int) $timeout;
}
if (isset($userAgent))
{
$options[CURLOPT_USERAGENT] = $userAgent;
}
$options[CURLOPT_RETURNTRANSFER] =
true;
$options[CURLOPT_HTTPHEADER][] =
'Expect:';
$options[CURLOPT_FOLLOWLOCATION] = (bool) $this->options->get(
'follow_location',
true);
$content = curl_exec($ch);
if (!is_string($content))
{
$message = curl_error($ch);
if (empty($message))
{
$message = 'No HTTP response received';
}
throw new RuntimeException($message);
}
$info = curl_getinfo($ch);
curl_close($ch);
}