[WebSocket] RFC Protocol Compliance

Refs #13
Fixed AB tests: 2.5, 4.*
RFC fails connections on bad control frames
This commit is contained in:
Chris Boden 2012-06-16 11:49:46 -04:00
parent ed83f67a84
commit 653d8fb482
2 changed files with 11 additions and 15 deletions

View File

@ -93,27 +93,19 @@ class RFC6455 implements VersionInterface {
$frame = $from->WebSocket->frame; $frame = $from->WebSocket->frame;
if (!$frame->isMasked()) { if (!$frame->isMasked()) {
unset($from->WebSocket->frame); return $from->close($frame::CLOSE_PROTOCOL);
$from->send($this->newFrame($frame::CLOSE_PROTOCOL, true, $frame::OP_CLOSE));
$from->getConnection()->close();
return;
} }
$opcode = $frame->getOpcode(); $opcode = $frame->getOpcode();
if ($opcode > 2) { if ($opcode > 2) {
if ($frame->getPayloadLength() > 125) {
return $from->close($frame::CLOSE_PROTOCOL);
}
switch ($opcode) { switch ($opcode) {
case $frame::OP_CLOSE: case $frame::OP_CLOSE:
$from->close($frame->getPayload()); return $from->close($frame);
/*
$from->send($frame->unMaskPayload());
$from->getConnection()->close();
*/
// $from->send(Frame::create(Frame::CLOSE_NORMAL, true, Frame::OP_CLOSE));
return;
break; break;
case $frame::OP_PING: case $frame::OP_PING:
$from->send($this->newFrame($frame->getPayload(), true, $frame::OP_PONG)); $from->send($this->newFrame($frame->getPayload(), true, $frame::OP_PONG));

View File

@ -20,7 +20,11 @@ class Connection extends AbstractConnectionDecorator {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function close($code = 1000) { public function close($code = 1000) {
$this->send(new Frame($code, true, Frame::OP_CLOSE)); if ($code instanceof DataInterface) {
$this->send($code);
} else {
$this->send(new Frame(Frame::encode(sprintf('%016b', $code)), true, Frame::OP_CLOSE));
}
$this->getConnection()->close(); $this->getConnection()->close();
} }