public function __construct($url, $method = 'GET', $timeout = 180)
{
$this->method = strtoupper($method);
$this->url = $url;
$this->set_timeout($timeout);
// load the proxy configuration, if it exists
$default = new \stdClass();
$proxy = Config::get('proxy', $default);
if (isset($proxy->server)) {
$this->set_config(array('proxy' => (array) $proxy));
}
// populate the default proxy exceptions list, since we can't up there
$this->config['proxy']['exceptions'] = array_merge($this->config['proxy']['exceptions'], array('localhost', '127.0.0.1', '::1'));
// these next two could be duplicates of 'localhost' and 127.0.0.1 / ::1 if you're on localhost - that's ok
if (isset($_SERVER['SERVER_NAME'])) {
$this->config['proxy']['exceptions'][] = $_SERVER['SERVER_NAME'];
}
if (isset($_SERVER['SERVER_ADDR'])) {
$this->config['proxy']['exceptions'][] = $_SERVER['SERVER_ADDR'];
}
$this->user_agent .= '/' . Version::get_habariversion();
$this->add_header(array('User-Agent' => $this->user_agent));
// if they've manually specified that we should not use curl, use sockets instead
if (Config::get('remote_request_processor') == 'socket') {
$this->processor = new SocketRequestProcessor();
} else {
// otherwise, see if we can use curl and fall back to sockets if not
if (function_exists('curl_init') && !(ini_get('safe_mode') || ini_get('open_basedir'))) {
$this->processor = new CURLRequestProcessor();
} else {
$this->processor = new SocketRequestProcessor();
}
}
}