获取v1的swift的token
null Module_Storage_Driver_Swift::get_real_token_v1( )
protected function get_real_token_v1()
{
$headers = array
(
'Host' => $this->host,
'X-Auth-User' => $this->account,
'X-Auth-Key' => $this->key,
'Content-Length' => 0,
);
if (IS_DEBUG)Core::debug()->info($this->protocol .'://'. $this->account . '@' . $this->host . ($this->port!=80 && $this->port!=443?':'.$this->port:'') . '/' . $this->token_api_version, 'Swift get token url');
$fp = $this->fp($this->protocol, $this->host, $this->port, $this->timeout);
$message = $this->build_request_line('GET', '/'. $this->token_api_version) . $this->build_headers($headers);
fwrite($fp, $message);
$rs = $this->read($fp);
try
{
if ($rs['code']<200 || $rs['code']>=300)
{
throw new Exception(__('Swift get token error. Code: :code.', array(':code'=>$rs['code'])));
}
# 获取token
if (isset($rs['header']['X-Auth-Token']))
{
$this->token = $rs['header']['X-Auth-Token'];
}
else
{
throw new Exception(__('Swift get token error.not found X-Auth-Token'));
}
# 获取Storage URL
if (isset($rs['header']['X-Storage-Url']))
{
$this->storage_url = $rs['header']['X-Storage-Url'];
$h = parse_url($this->storage_url);
$this->storage_host = $h['host'];
$this->storage_path = $h['path'];
$this->storage_protocol = $h['scheme'];
$this->storage_port = $h['port']?$h['port']:$h['scheme']=='https'?443:80;
if ($this->storage_url)
{
$conection_hash1 = $this->get_connection_hash();
$conection_hash2 = $this->get_connection_hash(true);
if ($conection_hash1==$conection_hash2)
{
# 将连接加到$connections里复用
Storage_Driver_Swift::set_connection($conection_hash1, $fp);
}
else
{
# 不是同一个服务器,关闭token服务器连接
fclose($fp);
}
}
}
else
{
throw new Exception(__('Swift get token error.not found X-Storage-Url'));
}
if (IS_DEBUG)Core::debug()->info($this->token, 'Swift Token');
}
catch (Exception $e)
{
fclose($fp);
throw $e;
}
}