Skip to content

Commit

Permalink
Merge branch 'psr7-multi-streamer'
Browse files Browse the repository at this point in the history
  • Loading branch information
cboden committed Feb 20, 2016
2 parents f93eb36 + 49cfd1e commit cbd376e
Show file tree
Hide file tree
Showing 35 changed files with 1,865 additions and 619 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
composer.lock
vendor
tests/ab/reports
reports
20 changes: 20 additions & 0 deletions .travis.yml
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011-2014 Chris Boden
Copyright (c) 2011-2016 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
Expand Down
15 changes: 7 additions & 8 deletions README.md
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.
48 changes: 25 additions & 23 deletions composer.json
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"
}
}
27 changes: 27 additions & 0 deletions phpunit.xml.dist
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>
31 changes: 0 additions & 31 deletions src/Encoding/ToggleableValidator.php

This file was deleted.

93 changes: 0 additions & 93 deletions src/Encoding/Validator.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Encoding/ValidatorInterface.php

This file was deleted.

53 changes: 53 additions & 0 deletions src/Handshake/ClientNegotiator.php
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;
}
}
47 changes: 47 additions & 0 deletions src/Handshake/NegotiatorInterface.php
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);
}
Loading

0 comments on commit cbd376e

Please sign in to comment.