Compare commits

...

5 Commits

Author SHA1 Message Date
a-sansara
a8f0981377 composer.json dev 2017-03-21 03:45:09 +01:00
a-sansara
7d9da4ac73 version 1.3.3 - manage responseHeader 2017-03-21 03:43:25 +01:00
a-sansara
94f5dcd4e5 fix invalid server response 2017-03-21 03:41:54 +01:00
a-sansara
fb15b5652a amend response Header 2017-03-21 02:54:36 +01:00
a-sansara
20399c4ae7 manage headerResponse 2017-03-21 01:20:29 +01:00
2 changed files with 40 additions and 12 deletions

View File

@ -18,6 +18,7 @@
},
"require" : {
"php" : ">=5.4",
"meta-tech/pws-auth" : "^2.1"
"meta-tech/pws-auth" : "@dev",
"symfony/yaml": "^3.2"
}
}

View File

@ -42,6 +42,9 @@ class Client
/*! @protected @var Mtc\Core\Auth\Authenticator $authenticator */
protected $authenticator;
/*! @protected @var str $responseToken */
protected $responseToken;
/*!
* desc
*
@ -173,6 +176,8 @@ class Client
private function _buildHeader($sessid=null)
{
$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;
}
@ -262,14 +267,31 @@ class Client
}
if (count($header) > 0) curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// curl_setopt($curl, CURLOPT_HEADERFUNCTION, array($this, "HandleHeaderLine"));
$rs = curl_exec($curl);
$exectime = number_format(((microtime(true)-$stime)),5);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$respheader = substr($rs, 0, $size);
$body = substr($rs, $size);
$response = json_decode($body);
$url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
$rs = curl_exec($curl);
$exectime = number_format(((microtime(true)-$stime)),5);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$respheader = substr($rs, 0, $size);
$authresponse = false;
try {
$lines = explode(PHP_EOL, $respheader);
$arrheader = [];
foreach($lines as $line) {
if (!empty($line)) {
$match = preg_split('/: /', $line, 2);
if (count($match)==2) {
$arrheader[$match[0]] = trim($match[1]);
}
}
}
$authresponse = isset($arrheader['Pws-Response']) && $arrheader['Pws-Response'] == $this->responseToken;
}
catch(\Exception $e) {
}
$body = substr($rs, $size);
$response = json_decode($body);
$url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
if ($status == 0) {
throw new \Exception(curl_error($curl));
}
@ -285,6 +307,7 @@ class Client
}
}
if ($this->config['debug']) {
$responseToken = $this->responseToken;
$respcontent = null;
if (is_object($response)) {
$respcontent = clone $response;
@ -316,7 +339,7 @@ class Client
'HEADER' => $this->authenticator->readHeader($header),
'PARAMS' => $data,
'METHOD' => $method,
'RESPONSE' => compact('date', 'uri', 'status') + ['curl' => $rs, 'response' => $respcontent]
'RESPONSE' => compact('date', 'uri', 'status', 'responseToken', 'authresponse') + ['curl' => $rs, 'response' => $respcontent]
], true) . Formatter::LF;
array_unshift($tags, $traces);
$this->formatter->writeTags($tags);
@ -324,11 +347,15 @@ class Client
case self::VERBOOSE :
array_unshift($tags, Formatter::LF);
$tags[] = var_export(compact('status')+['response' => $respcontent], true);
$tags[] = var_export(compact('status', 'authresponse')+['response' => $respcontent], true);
$this->formatter->writeTags($tags);
break;
}
return compact('date', 'uri', 'response', 'status', 'exectime');
if (!$authresponse) {
$response->done = false;
$response->msg = 'server response not authenticated !';
}
return compact('date', 'uri', 'response', 'status', 'exectime', 'authresponse');
}
}