Cleanup
This commit is contained in:
parent
0be4299fd6
commit
777e928cea
@ -39,7 +39,7 @@ class Hixie76 implements VersionInterface {
|
|||||||
* @throws \UnderflowException If there hasn't been enough data received
|
* @throws \UnderflowException If there hasn't been enough data received
|
||||||
*/
|
*/
|
||||||
public function handshake(RequestInterface $request) {
|
public function handshake(RequestInterface $request) {
|
||||||
$body = substr($request->getBody(), 0, 8);
|
$body = substr($request->getBody(), 0, 8);
|
||||||
if (8 !== strlen($body)) {
|
if (8 !== strlen($body)) {
|
||||||
throw new \UnderflowException("Not enough data received to issue challenge response");
|
throw new \UnderflowException("Not enough data received to issue challenge response");
|
||||||
}
|
}
|
||||||
|
92
WsServer.php
92
WsServer.php
@ -88,54 +88,54 @@ class WsServer implements MessageComponentInterface {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function onMessage(ConnectionInterface $from, $msg) {
|
public function onMessage(ConnectionInterface $from, $msg) {
|
||||||
if (true !== $from->WebSocket->established) {
|
if (true === $from->WebSocket->established) {
|
||||||
if (isset($from->WebSocket->request)) {
|
return $from->WebSocket->version->onMessage($this->connections[$from], $msg);
|
||||||
$from->WebSocket->request->getBody()->write($msg);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
if (null === ($request = $this->reqParser->onMessage($from, $msg))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (\OverflowException $oe) {
|
|
||||||
return $this->close($from, 413);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->versioner->isVersionEnabled($request)) {
|
|
||||||
return $this->close($from);
|
|
||||||
}
|
|
||||||
|
|
||||||
$from->WebSocket->request = $request;
|
|
||||||
$from->WebSocket->version = $this->versioner->getVersion($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$response = $from->WebSocket->version->handshake($from->WebSocket->request);
|
|
||||||
} catch (\UnderflowException $e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$response->setHeader('X-Powered-By', \Ratchet\VERSION);
|
|
||||||
|
|
||||||
// This needs to be refactored later on, incorporated with routing
|
|
||||||
if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($from->WebSocket->request->getTokenizedHeader('Sec-WebSocket-Protocol', ',')))) {
|
|
||||||
$response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
|
|
||||||
}
|
|
||||||
|
|
||||||
$from->send((string)$response);
|
|
||||||
|
|
||||||
if (101 != $response->getStatusCode()) {
|
|
||||||
return $from->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
$upgraded = $from->WebSocket->version->upgradeConnection($from, $this->_decorating);
|
|
||||||
|
|
||||||
$this->connections->attach($from, $upgraded);
|
|
||||||
|
|
||||||
$upgraded->WebSocket->established = true;
|
|
||||||
|
|
||||||
return $this->_decorating->onOpen($upgraded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$from->WebSocket->version->onMessage($this->connections[$from], $msg);
|
if (isset($from->WebSocket->request)) {
|
||||||
|
$from->WebSocket->request->getBody()->write($msg);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (null === ($request = $this->reqParser->onMessage($from, $msg))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (\OverflowException $oe) {
|
||||||
|
return $this->close($from, 413);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->versioner->isVersionEnabled($request)) {
|
||||||
|
return $this->close($from);
|
||||||
|
}
|
||||||
|
|
||||||
|
$from->WebSocket->request = $request;
|
||||||
|
$from->WebSocket->version = $this->versioner->getVersion($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $from->WebSocket->version->handshake($from->WebSocket->request);
|
||||||
|
} catch (\UnderflowException $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This needs to be refactored later on, incorporated with routing
|
||||||
|
if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($from->WebSocket->request->getTokenizedHeader('Sec-WebSocket-Protocol', ',')))) {
|
||||||
|
$response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->setHeader('X-Powered-By', \Ratchet\VERSION);
|
||||||
|
$from->send((string)$response);
|
||||||
|
|
||||||
|
if (101 != $response->getStatusCode()) {
|
||||||
|
return $from->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
$upgraded = $from->WebSocket->version->upgradeConnection($from, $this->_decorating);
|
||||||
|
|
||||||
|
$this->connections->attach($from, $upgraded);
|
||||||
|
|
||||||
|
$upgraded->WebSocket->established = true;
|
||||||
|
|
||||||
|
return $this->_decorating->onOpen($upgraded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user