aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2016-05-31 23:21:03 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2016-06-17 17:04:44 +0200
commit866dba25862b1aea27cff322b9294b156ffc6b48 (patch)
tree9fb801e0201761b9f74b95da5e3a3e0840c30970
parent6f59de85380b3ad02cd355b7300ccdca996aab87 (diff)
downloadWebsocket-866dba25862b1aea27cff322b9294b156ffc6b48.zip
Websocket-866dba25862b1aea27cff322b9294b156ffc6b48.tar.gz
Websocket-866dba25862b1aea27cff322b9294b156ffc6b48.tar.bz2
Client: Extract the `getNewChallenge` method.
-rw-r--r--Client.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/Client.php b/Client.php
index 6e0131c..a1e2df7 100644
--- a/Client.php
+++ b/Client.php
@@ -159,8 +159,6 @@ class Client extends Connection
*/
protected function doHandshake()
{
- static $_tail = ['A', 'Q', 'g', 'w'];
-
$connection = $this->getConnection();
$connection->connect();
@@ -170,10 +168,7 @@ class Client extends Connection
$connection->setStreamBlocking(true);
- $key =
- substr(base64_encode(Consistency::uuid()), 0, 21) .
- $_tail[mt_rand(0, 3)] . '==';
-
+ $key = $this->getNewChallenge();
$expected = base64_encode(sha1($key . Protocol\Rfc6455::GUID, true));
if (null === $host = $this->getHost()) {
@@ -231,6 +226,20 @@ class Client extends Connection
}
/**
+ * Generate a challenge.
+ *
+ * @return string
+ */
+ public function getNewChallenge()
+ {
+ static $_tail = ['A', 'Q', 'g', 'w'];
+
+ return
+ substr(base64_encode(Consistency::uuid()), 0, 21) .
+ $_tail[mt_rand(0, 3)] . '==';
+ }
+
+ /**
* Close a specific node/connection.
*
* @param int $code Code (please, see