-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,865 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
composer.lock | ||
vendor | ||
tests/ab/reports | ||
reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7 | ||
- hhvm | ||
|
||
before_install: | ||
- export PATH=$HOME/.local/bin:$PATH | ||
- pip install autobahntestsuite --user `whoami` | ||
- pip list autobahntestsuite --user `whoami` | ||
|
||
before_script: | ||
- composer install | ||
- sh tests/ab/run_ab_tests.sh | ||
|
||
script: | ||
- phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
# RFC6455 - The WebSocket Protocol | ||
|
||
This library is meant to be a protocol handler for the RFC6455 specification. | ||
[![Build Status](https://travis-ci.org/ratchetphp/RFC6455.svg?branch=master)](https://travis-ci.org/ratchetphp/RFC6455) | ||
|
||
--- | ||
This library a protocol handler for the RFC6455 specification. | ||
It contains components for both server and client side handshake and messaging protocol negotation. | ||
|
||
### A rough roadmap | ||
Aspects that are left open to interpertation in the specification are also left open in this library. | ||
It is up to the implementation to determine how those interpertations are to be dealt with. | ||
|
||
* v0.1 is the initial split from Ratchet/v0.3.2 as-is. In this state it currently relies on some of Ratchet's interfaces. | ||
* v0.2 will be more framework agnostic and will not require any interfaces from Ratchet. A dependency on Guzzle (or hopefully PSR-7) may be required. | ||
* v0.3 will look into performance tuning. No more expected exceptions. | ||
* v0.4 extension support | ||
* v1.0 when all the bases are covered | ||
This library is independent, framework agnostic, and does not deal with any I/O. | ||
HTTP upgrade negotiation integration points are handled with PSR-7 interfaces. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
{ | ||
"name": "ratchet/rfc6455" | ||
, "type": "library" | ||
, "description": "RFC6455 protocol handler" | ||
, "keywords": ["WebSockets"] | ||
, "homepage": "http://socketo.me" | ||
, "license": "MIT" | ||
, "authors": [ | ||
{ | ||
"name": "Chris Boden" | ||
, "email": "[email protected]" | ||
, "role": "Developer" | ||
} | ||
] | ||
, "support": { | ||
"forum": "https://groups.google.com/forum/#!forum/ratchet-php" | ||
"name": "ratchet/rfc6455", | ||
"type": "library", | ||
"description": "RFC6455 WebSocket protocol handler", | ||
"keywords": ["WebSockets", "websocket", "RFC6455"], | ||
"homepage": "http://socketo.me", | ||
"license": "MIT", | ||
"authors": [{ | ||
"name": "Chris Boden" | ||
, "email": "[email protected]" | ||
, "role": "Developer" | ||
}], | ||
"support": { | ||
"forum": "https://groups.google.com/forum/#!forum/ratchet-php" | ||
, "issues": "https://github.com/ratchetphp/RFC6455/issues" | ||
, "irc": "irc://irc.freenode.org/reactphp" | ||
} | ||
, "autoload": { | ||
, "irc": "irc://irc.freenode.org/reactphp" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Ratchet\\WebSocket\\": "src" | ||
"Ratchet\\RFC6455\\": "src" | ||
} | ||
} | ||
, "require": { | ||
"php": ">=5.3.9" | ||
, "guzzle/http": "~3.6" | ||
}, | ||
"require": { | ||
"php": ">=5.4.2", | ||
"guzzlehttp/psr7": "^1.0" | ||
}, | ||
"require-dev": { | ||
"react/http": "^0.4.1", | ||
"react/socket-client": "^0.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
forceCoversAnnotation="true" | ||
mapTestClassNameToCoveredClassName="true" | ||
bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
syntaxCheck="false" | ||
stopOnError="false" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="tests"> | ||
<directory>tests</directory> | ||
<exclude> | ||
<directory>test/ab</directory> | ||
</exclude> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace Ratchet\RFC6455\Handshake; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\UriInterface; | ||
use GuzzleHttp\Psr7\Request; | ||
|
||
class ClientNegotiator { | ||
/** | ||
* @var ResponseVerifier | ||
*/ | ||
private $verifier; | ||
|
||
/** | ||
* @var \Psr\Http\Message\RequestInterface | ||
*/ | ||
private $defaultHeader; | ||
|
||
function __construct() { | ||
$this->verifier = new ResponseVerifier; | ||
|
||
$this->defaultHeader = new Request('GET', '', [ | ||
'Connection' => 'Upgrade' | ||
, 'Upgrade' => 'websocket' | ||
, 'Sec-WebSocket-Version' => $this->getVersion() | ||
, 'User-Agent' => "RatchetRFC/0.0.0" | ||
]); | ||
} | ||
|
||
public function generateRequest(UriInterface $uri) { | ||
return $this->defaultHeader->withUri($uri) | ||
->withHeader("Sec-WebSocket-Key", $this->generateKey()); | ||
} | ||
|
||
public function validateResponse(RequestInterface $request, ResponseInterface $response) { | ||
return $this->verifier->verifyAll($request, $response); | ||
} | ||
|
||
public function generateKey() { | ||
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwzyz1234567890+/='; | ||
$charRange = strlen($chars) - 1; | ||
$key = ''; | ||
for ($i = 0; $i < 16; $i++) { | ||
$key .= $chars[mt_rand(0, $charRange)]; | ||
} | ||
|
||
return base64_encode($key); | ||
} | ||
|
||
public function getVersion() { | ||
return 13; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace Ratchet\RFC6455\Handshake; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* A standard interface for interacting with the various version of the WebSocket protocol | ||
* @todo Look in to extension support | ||
*/ | ||
interface NegotiatorInterface { | ||
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; | ||
|
||
/** | ||
* Given an HTTP header, determine if this version should handle the protocol | ||
* @param RequestInterface $request | ||
* @return bool | ||
*/ | ||
function isProtocol(RequestInterface $request); | ||
|
||
/** | ||
* Although the version has a name associated with it the integer returned is the proper identification | ||
* @return int | ||
*/ | ||
function getVersionNumber(); | ||
|
||
/** | ||
* Perform the handshake and return the response headers | ||
* @param RequestInterface $request | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
function handshake(RequestInterface $request); | ||
|
||
/** | ||
* Add supported protocols. If the request has any matching the response will include one | ||
* @param array $protocols | ||
*/ | ||
function setSupportedSubProtocols(array $protocols); | ||
|
||
/** | ||
* If enabled and support for a subprotocol has been added handshake | ||
* will not upgrade if a match between request and supported subprotocols | ||
* @param boolean $enable | ||
* @todo Consider extending this interface and moving this there. | ||
* The spec does says the server can fail for this reason, but | ||
it is not a requirement. This is an implementation detail. | ||
*/ | ||
function setStrictSubProtocolCheck($enable); | ||
} |
Oops, something went wrong.