wip
This commit is contained in:
parent
1cfe2c8776
commit
a632b43b56
|
|
@ -8,7 +8,8 @@ use Ratchet\Http\HttpServerInterface;
|
|||
use Ratchet\MessageComponentInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
class OriginCheck implements HttpServerInterface {
|
||||
class OriginCheck implements HttpServerInterface
|
||||
{
|
||||
|
||||
use CloseResponseTrait;
|
||||
|
||||
|
|
@ -17,13 +18,14 @@ class OriginCheck implements HttpServerInterface {
|
|||
|
||||
protected $allowedOrigins = [];
|
||||
|
||||
public function __construct(MessageComponentInterface $component, array $allowedOrigins = []) {
|
||||
public function __construct(MessageComponentInterface $component, array $allowedOrigins = [])
|
||||
{
|
||||
$this->_component = $component;
|
||||
$this->allowedOrigins = $allowedOrigins;
|
||||
}
|
||||
|
||||
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null) {
|
||||
|
||||
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null)
|
||||
{
|
||||
if ($request->hasHeader('Origin')) {
|
||||
$this->verifyOrigin($connection, $request);
|
||||
}
|
||||
|
|
@ -31,15 +33,18 @@ class OriginCheck implements HttpServerInterface {
|
|||
return $this->_component->onOpen($connection, $request);
|
||||
}
|
||||
|
||||
function onMessage(ConnectionInterface $from, $msg) {
|
||||
function onMessage(ConnectionInterface $from, $msg)
|
||||
{
|
||||
return $this->_component->onMessage($from, $msg);
|
||||
}
|
||||
|
||||
function onClose(ConnectionInterface $connection) {
|
||||
function onClose(ConnectionInterface $connection)
|
||||
{
|
||||
return $this->_component->onClose($connection);
|
||||
}
|
||||
|
||||
function onError(ConnectionInterface $connection, \Exception $e) {
|
||||
function onError(ConnectionInterface $connection, \Exception $e)
|
||||
{
|
||||
return $this->_component->onError($connection, $e);
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +53,7 @@ class OriginCheck implements HttpServerInterface {
|
|||
$header = (string)$request->getHeader('Origin')[0];
|
||||
$origin = parse_url($header, PHP_URL_HOST) ?: $header;
|
||||
|
||||
if (! empty($this->allowedOrigins) && !in_array($origin, $this->allowedOrigins)) {
|
||||
if (!empty($this->allowedOrigins) && !in_array($origin, $this->allowedOrigins)) {
|
||||
return $this->close($connection, 403);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue