[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 5c521af229
commit f0d605a42e
2 changed files with 11 additions and 15 deletions

View File

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

View File

@ -20,7 +20,11 @@ class Connection extends AbstractConnectionDecorator {
* {@inheritdoc}
*/
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();
}