manage headerResponse

This commit is contained in:
a-sansara 2017-03-21 01:20:29 +01:00
parent 8cecfa057f
commit 20399c4ae7

View File

@ -42,6 +42,9 @@ class Client
/*! @protected @var Mtc\Core\Auth\Authenticator $authenticator */ /*! @protected @var Mtc\Core\Auth\Authenticator $authenticator */
protected $authenticator; protected $authenticator;
/*! @protected @var str $responseToken */
protected $responseToken;
/*! /*!
* desc * desc
* *
@ -173,6 +176,8 @@ class Client
private function _buildHeader($sessid=null) private function _buildHeader($sessid=null)
{ {
$header = $this->authenticator->generateHeader($this->config['login'], $this->config['key'], $sessid); $header = $this->authenticator->generateHeader($this->config['login'], $this->config['key'], $sessid);
$token = $this->authenticator->getToken($this->authenticator->readHeader($header));
$this->responseToken = $this->authenticator->generateResponseHeader($token, $this->config['login']);
return $header; return $header;
} }
@ -267,6 +272,24 @@ class Client
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$respheader = substr($rs, 0, $size); $respheader = substr($rs, 0, $size);
$authresponse = false;
try {
$lines = explode(PHP_EOL, $respheader);
var_dump(compact('lines'));
$arrheader = [];
foreach($lines as $line) {
$match = preg_split('/:/', $line, 1);
if (count($match)==2) {
$arrheader[$match[0]] = trim($arrheader[$match[1]]);
}
}
$h = $this->authenticator->readHeader($arrheader);
var_dump(compact('h'));
$authresponse = isset($h['Pws-Response']) && $h['Pws-Response'] == $this->responseToken;
}
catch(\Exception $e) {
}
$body = substr($rs, $size); $body = substr($rs, $size);
$response = json_decode($body); $response = json_decode($body);
$url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
@ -328,7 +351,7 @@ class Client
$this->formatter->writeTags($tags); $this->formatter->writeTags($tags);
break; break;
} }
return compact('date', 'uri', 'response', 'status', 'exectime'); return compact('date', 'uri', 'response', 'status', 'exectime', 'authresponse');
} }
} }