From fc9401f04a3aca5abb22f87ebc210de8afe11d32 Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Tue, 10 Apr 2018 21:50:16 +0200 Subject: Initial Commit --- .../src/Ratchet/Http/CloseResponseTrait.php | 22 +++++ .../ratchet/src/Ratchet/Http/HttpRequestParser.php | 64 +++++++++++++++ .../cboden/ratchet/src/Ratchet/Http/HttpServer.php | 76 +++++++++++++++++ .../src/Ratchet/Http/HttpServerInterface.php | 14 ++++ .../src/Ratchet/Http/NoOpHttpServerController.php | 18 ++++ .../ratchet/src/Ratchet/Http/OriginCheck.php | 65 +++++++++++++++ .../cboden/ratchet/src/Ratchet/Http/Router.php | 96 ++++++++++++++++++++++ 7 files changed, 355 insertions(+) create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/CloseResponseTrait.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpRequestParser.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServerInterface.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/NoOpHttpServerController.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/OriginCheck.php create mode 100644 assets/php/vendor/cboden/ratchet/src/Ratchet/Http/Router.php (limited to 'assets/php/vendor/cboden/ratchet/src/Ratchet/Http') diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/CloseResponseTrait.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/CloseResponseTrait.php new file mode 100644 index 0000000..abdf5c4 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/CloseResponseTrait.php @@ -0,0 +1,22 @@ + \Ratchet\VERSION + ], $additional_headers)); + + $conn->send(gPsr\str($response)); + $conn->close(); + } +} \ No newline at end of file diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpRequestParser.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpRequestParser.php new file mode 100644 index 0000000..9c44114 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpRequestParser.php @@ -0,0 +1,64 @@ +httpBuffer)) { + $context->httpBuffer = ''; + } + + $context->httpBuffer .= $data; + + if (strlen($context->httpBuffer) > (int)$this->maxSize) { + throw new \OverflowException("Maximum buffer size of {$this->maxSize} exceeded parsing HTTP header"); + } + + if ($this->isEom($context->httpBuffer)) { + $request = $this->parse($context->httpBuffer); + + unset($context->httpBuffer); + + return $request; + } + } + + /** + * Determine if the message has been buffered as per the HTTP specification + * @param string $message + * @return boolean + */ + public function isEom($message) { + return (boolean)strpos($message, static::EOM); + } + + /** + * @param string $headers + * @return \Psr\Http\Message\RequestInterface + */ + public function parse($headers) { + return gPsr\parse_request($headers); + } +} diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php new file mode 100644 index 0000000..bbd8d53 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php @@ -0,0 +1,76 @@ +_httpServer = $component; + $this->_reqParser = new HttpRequestParser; + } + + /** + * {@inheritdoc} + */ + public function onOpen(ConnectionInterface $conn) { + $conn->httpHeadersReceived = false; + } + + /** + * {@inheritdoc} + */ + public function onMessage(ConnectionInterface $from, $msg) { + if (true !== $from->httpHeadersReceived) { + try { + if (null === ($request = $this->_reqParser->onMessage($from, $msg))) { + return; + } + } catch (\OverflowException $oe) { + return $this->close($from, 413); + } + + $from->httpHeadersReceived = true; + + return $this->_httpServer->onOpen($from, $request); + } + + $this->_httpServer->onMessage($from, $msg); + } + + /** + * {@inheritdoc} + */ + public function onClose(ConnectionInterface $conn) { + if ($conn->httpHeadersReceived) { + $this->_httpServer->onClose($conn); + } + } + + /** + * {@inheritdoc} + */ + public function onError(ConnectionInterface $conn, \Exception $e) { + if ($conn->httpHeadersReceived) { + $this->_httpServer->onError($conn, $e); + } else { + $this->close($conn, 500); + } + } +} diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServerInterface.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServerInterface.php new file mode 100644 index 0000000..2c37c49 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/HttpServerInterface.php @@ -0,0 +1,14 @@ +_component = $component; + $this->allowedOrigins += $allowed; + } + + /** + * {@inheritdoc} + */ + public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { + $header = (string)$request->getHeader('Origin')[0]; + $origin = parse_url($header, PHP_URL_HOST) ?: $header; + + if (!in_array($origin, $this->allowedOrigins)) { + return $this->close($conn, 403); + } + + return $this->_component->onOpen($conn, $request); + } + + /** + * {@inheritdoc} + */ + function onMessage(ConnectionInterface $from, $msg) { + return $this->_component->onMessage($from, $msg); + } + + /** + * {@inheritdoc} + */ + function onClose(ConnectionInterface $conn) { + return $this->_component->onClose($conn); + } + + /** + * {@inheritdoc} + */ + function onError(ConnectionInterface $conn, \Exception $e) { + return $this->_component->onError($conn, $e); + } +} \ No newline at end of file diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/Router.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/Router.php new file mode 100644 index 0000000..df7fe82 --- /dev/null +++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Http/Router.php @@ -0,0 +1,96 @@ +_matcher = $matcher; + $this->_noopController = new NoOpHttpServerController; + } + + /** + * {@inheritdoc} + * @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface + */ + public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { + if (null === $request) { + throw new \UnexpectedValueException('$request can not be null'); + } + + $conn->controller = $this->_noopController; + + $uri = $request->getUri(); + + $context = $this->_matcher->getContext(); + $context->setMethod($request->getMethod()); + $context->setHost($uri->getHost()); + + try { + $route = $this->_matcher->match($uri->getPath()); + } catch (MethodNotAllowedException $nae) { + return $this->close($conn, 405, array('Allow' => $nae->getAllowedMethods())); + } catch (ResourceNotFoundException $nfe) { + return $this->close($conn, 404); + } + + if (is_string($route['_controller']) && class_exists($route['_controller'])) { + $route['_controller'] = new $route['_controller']; + } + + if (!($route['_controller'] instanceof HttpServerInterface)) { + throw new \UnexpectedValueException('All routes must implement Ratchet\Http\HttpServerInterface'); + } + + $parameters = []; + foreach($route as $key => $value) { + if ((is_string($key)) && ('_' !== substr($key, 0, 1))) { + $parameters[$key] = $value; + } + } + $parameters = array_merge($parameters, gPsr\parse_query($uri->getQuery() ?: '')); + + $request = $request->withUri($uri->withQuery(gPsr\build_query($parameters))); + + $conn->controller = $route['_controller']; + $conn->controller->onOpen($conn, $request); + } + + /** + * {@inheritdoc} + */ + public function onMessage(ConnectionInterface $from, $msg) { + $from->controller->onMessage($from, $msg); + } + + /** + * {@inheritdoc} + */ + public function onClose(ConnectionInterface $conn) { + if (isset($conn->controller)) { + $conn->controller->onClose($conn); + } + } + + /** + * {@inheritdoc} + */ + public function onError(ConnectionInterface $conn, \Exception $e) { + if (isset($conn->controller)) { + $conn->controller->onError($conn, $e); + } + } +} -- cgit v1.2.3