Compare commits

...

9 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
a-sansara
8cecfa057f Merge branch 'master' of https://github.com/meta-tech/pws-client 2017-03-20 17:18:39 +01:00
a-sansara
a614f24061 fix style displaying in html mode 2017-03-20 17:17:57 +01:00
a-sansara
3e9f077187 add ssl options on config in README 2017-03-16 02:24:37 +01:00
a-sansara
44787b0f7d typo in README 2017-03-16 02:23:01 +01:00
4 changed files with 53 additions and 22 deletions

View File

@ -18,7 +18,7 @@ Or add the package to your `composer.json`.
```
"require": {
"meta-tech/pws-client" : "~1.3"
"meta-tech/pws-client" : "^1.3"
}
```
@ -50,7 +50,7 @@ if ($response->done) {
}
// post example
$client->post('/ws/person/222/update', [ 'firstname' => 'toto']);
$response = $client->post('/ws/person/222/update', [ 'firstname' => 'toto']);
if ($response->done) {
// do stuff
}
@ -69,6 +69,9 @@ if ($response->done) {
debug : 1
protocol : https://
hostname : pwsserver.docker
# ssl options
verifypeer : 0
verifyhost : 0
# file storing the server 's session id - must be out of DocumentRoot and read/writable by server
store : wsess
login : test
@ -95,7 +98,7 @@ However, meta-tech always return this simple Json Structure :
`{ done : boolean, msg : 'string contextual msg', data : whatever }`
see [ meta-tech/pws-server ](https://github.com/meta-tech/pws-server)
and [ meta-tech/sile-core ](https://github.com/meta-tech/silex-core)
and [ meta-tech/silex-core ](https://github.com/meta-tech/silex-core)
### License

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

@ -86,11 +86,11 @@ class Formatter
if (!$this->embedStyle) {
$this->embedStyle = true;
$style .= '<style type="text/css">'
. '.meta-tech-of-line { white-space:pre !important; background-color:black !important; color:white !important; font-weight:bold !important; font-family:monospace !important; padding:10px !important; margin-top:0 !important }'
. '.meta-tech-of-tag1 { color:#FB4E4E !important; }'
. '.meta-tech-of-tag2 { color:#20FF93 !important; }'
. '.meta-tech-of-tag3 { color:#FFDC58 !important; }'
. '.meta-tech-of-tag4 { color:#44A2D6 !important; }'
. '.meta-tech-of-line { font-size:13px !important; background-color:black !important; color:white !important; white-space:pre !important; font-weight:bold !important; font-family:\'monospace\' !important; padding:10px !important; margin-top:0 !important }'
. '.meta-tech-of-tag1 { color:#FB4E4E !important; }'
. '.meta-tech-of-tag2 { color:#20FF93 !important; }'
. '.meta-tech-of-tag3 { color:#FFDC58 !important; }'
. '.meta-tech-of-tag4 { color:#44A2D6 !important; }'
. '</style>';
}
return $style;
@ -128,7 +128,7 @@ class Formatter
{
$content = $value . ($newline ? self::LF : '');
if ($this->type == self::TYPE_HTML) {
$content = $this->embedStyleIfNeeded() . '<div class"meta-tech-ofline">'.$content.'</div>';
$content = $this->embedStyleIfNeeded() . '<div class="meta-tech-of-line">'.$content.'</div>';
}
echo $content;
}

View File

@ -42,6 +42,9 @@ class Client
/*! @protected @var Mtc\Core\Auth\Authenticator $authenticator */
protected $authenticator;
/*! @protected @var str $responseToken */
protected $responseToken;
/*!
* desc
*
@ -55,7 +58,7 @@ class Client
if (!is_array($config)) {
throw new \Exception('bad rest config');
}
$typeFormatter = $this->config['html_output'] ? Formatter::TYPE_HTML : Formatter::TYPE_CLI;
$typeFormatter = $config['html_output'] ? Formatter::TYPE_HTML : Formatter::TYPE_CLI;
$this->formatter = new Formatter($typeFormatter);
$this->config = $config;
$this->authenticator = $authenticator;
@ -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;
}
@ -267,6 +272,23 @@ class Client
$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);
@ -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');
}
}