Create a new request
string $method HTTP method:
string|Url $url HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the: full URL. If query string parameters are present they will be parsed as well.
array|Collection $headers HTTP headers:
public function __construct($method, $url, $headers = array()) {
$this->method = strtoupper($method);
$this->curlOptions = new Collection();
$this->params = new Collection();
$this
->setUrl($url);
if ($headers) {
// Special handling for multi-value headers
foreach ($headers as $key => $value) {
$lkey = strtolower($key);
// Deal with collisions with Host and Authorization
if ($lkey == 'host') {
$this
->setHeader($key, $value);
}
elseif ($lkey == 'authorization') {
$parts = explode(' ', $value);
if ($parts[0] == 'Basic' && isset($parts[1])) {
list($user, $pass) = explode(':', base64_decode($parts[1]));
$this
->setAuth($user, $pass);
}
else {
$this
->setHeader($key, $value);
}
}
else {
foreach ((array) $value as $v) {
$this
->addHeader($key, $v);
}
}
}
}
if (!$this
->hasHeader('User-Agent', true)) {
$this
->setHeader('User-Agent', Utils::getDefaultUserAgent());
}
$this
->setState(self::STATE_NEW);
}