From a604f348f8fbfba357e0ab1fdef6de85069ea0f3 Mon Sep 17 00:00:00 2001 From: Samuel CHEMLA Date: Sat, 20 Mar 2021 13:47:10 +0100 Subject: [PATCH] Update react/http to stable release --- README.md | 2 +- composer.json | 2 +- composer.lock | 60 +++++++++++++++++++++++++------- src/Middleware/StaticContent.php | 17 ++++++--- src/Model/RequestContext.php | 2 +- src/ServerFactory.php | 4 +-- 6 files changed, 66 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index f6e7c3f..0ce99d9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This framework is designed to build quick proofs of concepts. It is **not** mature enough to run in production environments, because: * it still contains synchronous blocking code - * react http itself is not stable + * it lacks a dependency (ioc) /configuration management ## License MIT diff --git a/composer.json b/composer.json index 89a515a..5398505 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=7.0", "ext-zlib": "*", "ext-json": "*", - "react/http": "^0.8.5", + "react/http": "^1.0", "zendframework/zend-validator": "^2.10", "zendframework/zend-filter": "^2.8", "psr/log": "^1.0", diff --git a/composer.lock b/composer.lock index 73fb941..490737c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a0188f5fc2f6b5e731855d9fee131d82", + "content-hash": "d7f56e942441ff5f13e86e8e6eb48fcf", "packages": [ { "name": "container-interop/container-interop", @@ -456,30 +456,35 @@ }, { "name": "react/http", - "version": "v0.8.5", + "version": "v1.0.0", "source": { "type": "git", "url": "https://github.com/reactphp/http.git", - "reference": "5f2ce4da6d30779ab1e6b95a0afac3e0e5595f64" + "reference": "865694453c95122f8972b9ed7961efb3c517fc5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/http/zipball/5f2ce4da6d30779ab1e6b95a0afac3e0e5595f64", - "reference": "5f2ce4da6d30779ab1e6b95a0afac3e0e5595f64", + "url": "https://api.github.com/repos/reactphp/http/zipball/865694453c95122f8972b9ed7961efb3c517fc5e", + "reference": "865694453c95122f8972b9ed7961efb3c517fc5e", "shasum": "" }, "require": { "evenement/evenement": "^3.0 || ^2.0 || ^1.0", "php": ">=5.3.0", + "psr/http-message": "^1.0", + "react/event-loop": "^1.0 || ^0.5", "react/promise": "^2.3 || ^1.2.1", "react/promise-stream": "^1.1", - "react/socket": "^1.0 || ^0.8.3", - "react/stream": "^1.0 || ^0.7.1", + "react/socket": "^1.1", + "react/stream": "^1.0 || ^0.7.5", "ringcentral/psr7": "^1.2" }, "require-dev": { "clue/block-react": "^1.1", - "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" + "clue/http-proxy-react": "^1.3", + "clue/reactphp-ssh-proxy": "^1.0", + "clue/socks-react": "^1.0", + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" }, "type": "library", "autoload": { @@ -491,16 +496,43 @@ "license": [ "MIT" ], - "description": "Event-driven, streaming plaintext HTTP and secure HTTPS server for ReactPHP", + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Event-driven, streaming HTTP client and server implementation for ReactPHP", "keywords": [ + "async", + "client", "event-driven", "http", + "http client", + "http server", "https", + "psr-7", "reactphp", "server", "streaming" ], - "time": "2019-10-29T14:17:24+00:00" + "time": "2020-07-11T13:29:43+00:00" }, { "name": "react/promise", @@ -868,6 +900,7 @@ "filter", "zf" ], + "abandoned": "laminas/laminas-filter", "time": "2018-12-17T16:00:04+00:00" }, { @@ -913,6 +946,7 @@ "stdlib", "zf" ], + "abandoned": "laminas/laminas-stdlib", "time": "2018-08-28T21:34:05+00:00" }, { @@ -986,6 +1020,7 @@ "validator", "zf2" ], + "abandoned": "laminas/laminas-validator", "time": "2018-12-13T21:23:15+00:00" } ], @@ -2613,5 +2648,6 @@ "ext-zlib": "*", "ext-json": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/src/Middleware/StaticContent.php b/src/Middleware/StaticContent.php index e467655..52e59ce 100644 --- a/src/Middleware/StaticContent.php +++ b/src/Middleware/StaticContent.php @@ -26,7 +26,9 @@ namespace PhpBg\MiniHttpd\Middleware; +use GuzzleHttp\Psr7\Stream; use Psr\Http\Message\ServerRequestInterface; +use React\EventLoop\LoopInterface; /** * Serve static files @@ -48,11 +50,18 @@ class StaticContent protected $mimeNamesByExtension; /** + * @var LoopInterface + */ + protected $loop; + + /** + * @param LoopInterface $loop * @param string $publicPath Full path to the directory that contain files to serve. Ex: /var/www/public * @param array $mimeNamesByExtension array of mimes names, by (unique) extension. E.g. ['html' => 'application/html'] */ - public function __construct(string $publicPath, array $mimeNamesByExtension) + public function __construct(LoopInterface $loop, string $publicPath, array $mimeNamesByExtension) { + $this->loop = $loop; if (!is_dir($publicPath)) { throw new \RuntimeException(); } @@ -80,12 +89,12 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) if ($mime !== null) { $headers['Content-Type'] = $mime; } - return new \React\Http\Response( + return new \React\Http\Message\Response( 200, $headers, // Beware that this won't achieve good performance and scalability, mainly because native php file streams may or not be blocking, who knows...? // @see https://bugs.php.net/bug.php?id=75538 - fopen($realPath, 'rb') + new Stream(fopen($realPath, 'rb')) ); } @@ -94,7 +103,7 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) } // If no next middleware, then issue a 404 not found - return new \React\Http\Response( + return new \React\Http\Message\Response( 404 ); } diff --git a/src/Model/RequestContext.php b/src/Model/RequestContext.php index 89276b0..dc45788 100644 --- a/src/Model/RequestContext.php +++ b/src/Model/RequestContext.php @@ -28,7 +28,7 @@ use PhpBg\MiniHttpd\Renderer\RendererInterface; use Psr\Http\Message\ResponseInterface; -use React\Http\Response; +use React\Http\Message\Response; /** * This class is used to pass data between all middlewares in both direction diff --git a/src/ServerFactory.php b/src/ServerFactory.php index 5e99a2c..e5b4d38 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -77,7 +77,7 @@ public static function createDefaultStack(ApplicationContext $applicationContext if (isset($applicationContext->publicPath) && file_exists($applicationContext->publicPath)) { $applicationContext->logger->notice("Serving *all* files from: $applicationContext->publicPath"); $applicationContext->logger->notice("Don't hide your secrets there"); - $middlewares[] = new StaticContent($applicationContext->publicPath, $mimeDb->getNamesByExtension()); + $middlewares[] = new StaticContent($applicationContext->loop, $applicationContext->publicPath, $mimeDb->getNamesByExtension()); } // Render responses @@ -111,7 +111,7 @@ public static function createDefaultStack(ApplicationContext $applicationContext public static function create(ApplicationContext $applicationContext): Server { $middlewares = static::createDefaultStack($applicationContext); - $server = new Server($middlewares); + $server = new Server($applicationContext->loop, ...$middlewares); // Log server errors $server->on('error', function ($exception) use ($applicationContext) {