diff --git a/LICENSE b/LICENSE index 7f8c128..52b4aef 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011-2016 Chris Boden +Copyright (c) 2011 Chris Boden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 0416b58..054a8fb 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,10 @@ }, "require": { "php": ">=5.4.2", - "guzzlehttp/psr7": "^1.0" + "guzzlehttp/psr7": "^2 || ^1.7" }, "require-dev": { - "phpunit/phpunit": "5.7.*", + "phpunit/phpunit": "^5.7", "react/socket": "^1.3" }, "scripts": { diff --git a/src/Messaging/Frame.php b/src/Messaging/Frame.php index 24b491e..63da6d2 100644 --- a/src/Messaging/Frame.php +++ b/src/Messaging/Frame.php @@ -327,15 +327,6 @@ class Frame implements FrameInterface { } return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT); - - // TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3) - - $applied = ''; - for ($i = 0, $len = strlen($payload); $i < $len; $i++) { - $applied .= $payload[$i] ^ $maskingKey[$i % static::MASK_LENGTH]; - } - - return $applied; } /** diff --git a/src/Messaging/MessageBuffer.php b/src/Messaging/MessageBuffer.php index d761786..e5d197b 100644 --- a/src/Messaging/MessageBuffer.php +++ b/src/Messaging/MessageBuffer.php @@ -117,10 +117,10 @@ class MessageBuffer { $memory_limit_bytes = static::getMemoryLimit(); if ($maxMessagePayloadSize === null) { - $maxMessagePayloadSize = $memory_limit_bytes / 4; + $maxMessagePayloadSize = (int)($memory_limit_bytes / 4); } if ($maxFramePayloadSize === null) { - $maxFramePayloadSize = $memory_limit_bytes / 4; + $maxFramePayloadSize = (int)($memory_limit_bytes / 4); } if (!is_int($maxFramePayloadSize) || $maxFramePayloadSize > 0x7FFFFFFFFFFFFFFF || $maxFramePayloadSize < 0) { // this should be interesting on non-64 bit systems diff --git a/tests/ab/clientRunner.php b/tests/ab/clientRunner.php index 8dd964b..c6becbc 100644 --- a/tests/ab/clientRunner.php +++ b/tests/ab/clientRunner.php @@ -1,4 +1,6 @@ 1 ? $argv[1] : "127.0.0.1"; $loop = React\EventLoop\Factory::create(); @@ -55,9 +57,9 @@ function getTestCases() { $deferred = new Deferred(); - $connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred) { + $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $testServer) { $cn = new ClientNegotiator(); - $cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001/getCaseCount')); + $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002/getCaseCount')); $rawResponse = ""; $response = null; @@ -72,7 +74,7 @@ function getTestCases() { if ($pos) { $data = substr($rawResponse, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4); - $response = \GuzzleHttp\Psr7\parse_response($rawResponse); + $response = Message::parseResponse($rawResponse); if (!$cn->validateResponse($cnRequest, $response)) { $connection->end(); @@ -101,7 +103,7 @@ function getTestCases() { } }); - $connection->write(\GuzzleHttp\Psr7\str($cnRequest)); + $connection->write(Message::toString($cnRequest)); }); return $deferred->promise(); @@ -120,10 +122,10 @@ function runTest($case) $deferred = new Deferred(); - $connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred, $casePath, $case) { + $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $casePath, $case, $testServer) { $cn = new ClientNegotiator( PermessageDeflateOptions::permessageDeflateSupported() ? PermessageDeflateOptions::createEnabled() : null); - $cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001' . $casePath)); + $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002' . $casePath)); $rawResponse = ""; $response = null; @@ -137,7 +139,7 @@ function runTest($case) if ($pos) { $data = substr($rawResponse, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4); - $response = \GuzzleHttp\Psr7\parse_response($rawResponse); + $response = Message::parseResponse($rawResponse); if (!$cn->validateResponse($cnRequest, $response)) { echo "Invalid response.\n"; @@ -167,7 +169,7 @@ function runTest($case) $deferred->resolve(); }); - $connection->write(\GuzzleHttp\Psr7\str($cnRequest)); + $connection->write(Message::toString($cnRequest)); }); return $deferred->promise(); @@ -179,12 +181,12 @@ function createReport() { $deferred = new Deferred(); - $connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred) { + $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $testServer) { // $reportPath = "/updateReports?agent=" . AGENT . "&shutdownOnComplete=true"; // we will stop it using docker now instead of just shutting down $reportPath = "/updateReports?agent=" . AGENT; $cn = new ClientNegotiator(); - $cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001' . $reportPath)); + $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002' . $reportPath)); $rawResponse = ""; $response = null; @@ -199,7 +201,7 @@ function createReport() { if ($pos) { $data = substr($rawResponse, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4); - $response = \GuzzleHttp\Psr7\parse_response($rawResponse); + $response = Message::parseResponse($rawResponse); if (!$cn->validateResponse($cnRequest, $response)) { $connection->end(); @@ -228,7 +230,7 @@ function createReport() { } }); - $connection->write(\GuzzleHttp\Psr7\str($cnRequest)); + $connection->write(Message::toString($cnRequest)); }); return $deferred->promise(); diff --git a/tests/ab/fuzzingserver.json b/tests/ab/fuzzingserver.json index 3a59bab..9f10403 100644 --- a/tests/ab/fuzzingserver.json +++ b/tests/ab/fuzzingserver.json @@ -1,5 +1,5 @@ { - "url": "ws://127.0.0.1:9001" + "url": "ws://127.0.0.1:9002" , "options": { "failByDrop": false } diff --git a/tests/ab/fuzzingserver_skip_deflate.json b/tests/ab/fuzzingserver_skip_deflate.json index 3b90fc3..9323191 100644 --- a/tests/ab/fuzzingserver_skip_deflate.json +++ b/tests/ab/fuzzingserver_skip_deflate.json @@ -1,5 +1,5 @@ { - "url": "ws://127.0.0.1:9001" + "url": "ws://127.0.0.1:9002" , "options": { "failByDrop": false } diff --git a/tests/ab/run_ab_tests.sh b/tests/ab/run_ab_tests.sh index 9c50d66..3df4a7d 100644 --- a/tests/ab/run_ab_tests.sh +++ b/tests/ab/run_ab_tests.sh @@ -6,13 +6,13 @@ if [ "$ABTEST" = "client" ]; then -d \ -v ${PWD}:/config \ -v ${PWD}/reports:/reports \ - -p 9001:9001 \ + -p 9002:9002 \ --name fuzzingserver \ crossbario/autobahn-testsuite wstest -m fuzzingserver -s /config/fuzzingserver$SKIP_DEFLATE.json sleep 5 if [ "$TRAVIS" != "true" ]; then echo "Running tests vs Autobahn test client" - ###docker run -it --rm --name abpytest crossbario/autobahn-testsuite wstest --mode testeeclient -w ws://host.docker.internal:9001 + ###docker run -it --rm --name abpytest crossbario/autobahn-testsuite wstest --mode testeeclient -w ws://host.docker.internal:9002 fi php -d memory_limit=256M clientRunner.php diff --git a/tests/ab/startServer.php b/tests/ab/startServer.php index f1d3b66..7c169c6 100644 --- a/tests/ab/startServer.php +++ b/tests/ab/startServer.php @@ -1,5 +1,6 @@ on('connection', function (React\Socket\ConnectionInterface $connection return; } $headerComplete = true; - $psrRequest = \GuzzleHttp\Psr7\parse_request($parts[0] . "\r\n\r\n"); + $psrRequest = Message::parseRequest($parts[0] . "\r\n\r\n"); $negotiatorResponse = $negotiator->handshake($psrRequest); $negotiatorResponse = $negotiatorResponse->withAddedHeader("Content-Length", "0"); if ($negotiatorResponse->getStatusCode() !== 101 && $psrRequest->getUri()->getPath() === '/shutdown') { - $connection->end(\GuzzleHttp\Psr7\str(new Response(200, [], 'Shutting down echo server.' . PHP_EOL))); + $connection->end(Message::toString(new Response(200, [], 'Shutting down echo server.' . PHP_EOL))); $socket->close(); return; }; - $connection->write(\GuzzleHttp\Psr7\str($negotiatorResponse)); + $connection->write(Message::toString($negotiatorResponse)); if ($negotiatorResponse->getStatusCode() !== 101) { $connection->end(); diff --git a/tests/unit/Handshake/ServerNegotiatorTest.php b/tests/unit/Handshake/ServerNegotiatorTest.php index c08b9f3..720bdf9 100644 --- a/tests/unit/Handshake/ServerNegotiatorTest.php +++ b/tests/unit/Handshake/ServerNegotiatorTest.php @@ -2,6 +2,7 @@ namespace Ratchet\RFC6455\Test\Unit\Handshake; +use GuzzleHttp\Psr7\Message; use Ratchet\RFC6455\Handshake\RequestVerifier; use Ratchet\RFC6455\Handshake\ServerNegotiator; use PHPUnit\Framework\TestCase; @@ -24,7 +25,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -53,7 +54,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -80,7 +81,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -107,7 +108,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -141,7 +142,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -175,7 +176,7 @@ Accept-Language: en-US,en;q=0.8 '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request); @@ -205,7 +206,7 @@ Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits '; - $request = \GuzzleHttp\Psr7\parse_request($requestText); + $request = Message::parseRequest($requestText); $response = $negotiator->handshake($request);