No Mask on Frame

HyBi spec says server shouldn't mask payloads when delivering to client - now allow user to specify to mask or not; WebSocket by default will not mask, Framing on its own will
This commit is contained in:
Chris Boden 2011-11-25 10:42:35 -05:00
parent 4de9caaa78
commit e6012d1685
4 changed files with 18 additions and 5 deletions

View File

@ -39,6 +39,8 @@ class App implements ApplicationInterface, ConfiguratorInterface {
, 'Hixie76' => null , 'Hixie76' => null
); );
protected $_mask_payload = false;
public function __construct(ApplicationInterface $app = null) { public function __construct(ApplicationInterface $app = null) {
if (null === $app) { if (null === $app) {
throw new \UnexpectedValueException("WebSocket requires an application to run"); throw new \UnexpectedValueException("WebSocket requires an application to run");
@ -171,7 +173,7 @@ class App implements ApplicationInterface, ConfiguratorInterface {
} }
$version = $command->getConnection()->WebSocket->version; $version = $command->getConnection()->WebSocket->version;
return $command->setMessage($version->frame($command->getMessage())); return $command->setMessage($version->frame($command->getMessage(), $this->_mask_payload));
} }
if ($command instanceof \Traversable) { if ($command instanceof \Traversable) {
@ -226,4 +228,14 @@ class App implements ApplicationInterface, ConfiguratorInterface {
unset($this->_versions[$name]); unset($this->_versions[$name]);
} }
/**
* Set the option to mask the payload upon sending to client
* If WebSocket is used as server, this should be false, client to true
* @param bool
* @todo User shouldn't have to know/set this, need to figure out how to do this automatically
*/
public function setMaskPayload($opt) {
$this->_mask_payload = (boolean)$opt;
}
} }

View File

@ -53,7 +53,7 @@ class Hixie76 implements VersionInterface {
return new Hixie76\Frame; return new Hixie76\Frame;
} }
public function frame($message) { public function frame($message, $mask = true) {
return chr(0) . $message . chr(255); return chr(0) . $message . chr(255);
} }

View File

@ -61,10 +61,10 @@ class HyBi10 implements VersionInterface {
* @param string * @param string
* @return string * @return string
*/ */
public function frame($message) { public function frame($message, $mask = true) {
$payload = $message; $payload = $message;
$type = 'text'; $type = 'text';
$masked = true; $masked = $mask;
$frameHead = array(); $frameHead = array();
$frame = ''; $frame = '';

View File

@ -35,8 +35,9 @@ interface VersionInterface {
/** /**
* @param string * @param string
* @param bool
* @return string * @return string
* @todo Change to use other classes, this will be removed eventually * @todo Change to use other classes, this will be removed eventually
*/ */
function frame($message); function frame($message, $mask = true);
} }