public function head($uri)
{
curl_setopt($this->curl, CURLOPT_HEADER, 1);
$full_url = $this->get_full_url($uri);
curl_setopt($this->curl, CURLOPT_URL, $full_url);
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($this->curl, CURLOPT_NOBODY, true);
// $this->headers is an associative array, to allow for overrides in set(), but
// curl_setopt() takes indexed array, so we need to convert.
$idxed_headers = array();
foreach ($this->headers as $name => $value) {
$idxed_headers[] = "{$name}: {$value}";
}
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $idxed_headers);
if (!empty($this->data) && is_array($this->data)) {
$data = http_build_query($this->data);
$this->header('Content-Length', strlen($data));
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $data);
}
$response = curl_exec($this->curl);
//reset defaults to allow clean re-use of the request object
$this->data = array();
$this->headers = array();
$this->method = '';
// Restore default values
curl_setopt($this->curl, CURLOPT_NOBODY, false);
curl_setopt($this->curl, CURLOPT_HEADER, false);
if (function_exists('http_parse_headers')) {
$headers = http_parse_headers($response);
} else {
$headers = $this->_http_parse_headers($response);
}
return array('code' => curl_getinfo($this->curl, CURLINFO_HTTP_CODE), 'meta' => curl_getinfo($this->curl), 'data' => $headers);
}