public function __construct($base_url = null)
{
if (!extension_loaded('curl')) {
throw new \ErrorException('cURL library is not loaded');
}
$this->curl = curl_init();
$this->id = uniqid('', true);
$this->setDefaultUserAgent();
$this->setDefaultJsonDecoder();
$this->setDefaultXmlDecoder();
$this->setDefaultTimeout();
$this->setOpt(CURLINFO_HEADER_OUT, true);
$this->setOpt(CURLOPT_HEADERFUNCTION, array($this, 'headerCallback'));
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
$this->headers = new CaseInsensitiveArray();
$this->setUrl($base_url);
}