Fixed sub-protocol negotiation support
This commit is contained in:
parent
d0d7b67ad7
commit
46487e756c
@ -52,6 +52,10 @@ class WsServer implements HttpServerInterface {
|
|||||||
$encodingValidator = new \Ratchet\RFC6455\Encoding\Validator;
|
$encodingValidator = new \Ratchet\RFC6455\Encoding\Validator;
|
||||||
$this->handshakeNegotiator = new \Ratchet\RFC6455\Handshake\Negotiator($encodingValidator);
|
$this->handshakeNegotiator = new \Ratchet\RFC6455\Handshake\Negotiator($encodingValidator);
|
||||||
$this->messageStreamer = new \Ratchet\RFC6455\Messaging\Streaming\MessageStreamer($encodingValidator);
|
$this->messageStreamer = new \Ratchet\RFC6455\Messaging\Streaming\MessageStreamer($encodingValidator);
|
||||||
|
|
||||||
|
if ($component instanceof WsServerInterface) {
|
||||||
|
$this->handshakeNegotiator->setSupportedSubProtocols($component->getSubProtocols());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,14 +74,6 @@ class WsServer implements HttpServerInterface {
|
|||||||
|
|
||||||
$response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION);
|
$response = $this->handshakeNegotiator->handshake($request)->withHeader('X-Powered-By', \Ratchet\VERSION);
|
||||||
|
|
||||||
// Probably moved to RFC lib
|
|
||||||
// $subHeader = $conn->WebSocket->request->getHeader('Sec-WebSocket-Protocol');
|
|
||||||
// if (count($subHeader) > 0) {
|
|
||||||
// if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($subHeader))) {
|
|
||||||
// $response = $response->withHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
$conn->send(gPsr\str($response));
|
$conn->send(gPsr\str($response));
|
||||||
|
|
||||||
if (101 != $response->getStatusCode()) {
|
if (101 != $response->getStatusCode()) {
|
||||||
@ -141,35 +137,7 @@ class WsServer implements HttpServerInterface {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setStrictSubProtocolCheck($enable) {
|
||||||
* @param string
|
$this->handshakeNegotiator->setStrictSubProtocolCheck($enable);
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isSubProtocolSupported($name) {
|
|
||||||
if (!$this->isSpGenerated) {
|
|
||||||
if ($this->component instanceof WsServerInterface) {
|
|
||||||
$this->acceptedSubProtocols = array_flip($this->component->getSubProtocols());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->isSpGenerated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_key_exists($name, $this->acceptedSubProtocols);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Traversable|null $requested
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getSubProtocolString(\Traversable $requested = null) {
|
|
||||||
if (null !== $requested) {
|
|
||||||
foreach ($requested as $sub) {
|
|
||||||
if ($this->isSubProtocolSupported($sub)) {
|
|
||||||
return $sub;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user