diff --git a/composer.json b/composer.json index f428ca0..5534da6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.2 || ^8.3 || ^8.4", "phunkie/phunkie": "^1.5", "phunkie/effect": "^1.4", - "phunkie/streams": "^1.4" + "phunkie/streams": "^1.5" }, "require-dev": { "phpunit/phpunit": "^10.0 || ^11.0", diff --git a/composer.lock b/composer.lock index 63d06bb..03a6a41 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b23fd3bc0d826699c8b65212b260241a", + "content-hash": "6c5179ebac6a139bec9bd7374a98271b", "packages": [ { "name": "phunkie/effect", @@ -120,16 +120,16 @@ }, { "name": "phunkie/streams", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/phunkie/streams.git", - "reference": "f9175ce2388fdd026b86f1384dd3aba63a132a83" + "reference": "45231191ff59597974acd40591c83926a76380d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phunkie/streams/zipball/f9175ce2388fdd026b86f1384dd3aba63a132a83", - "reference": "f9175ce2388fdd026b86f1384dd3aba63a132a83", + "url": "https://api.github.com/repos/phunkie/streams/zipball/45231191ff59597974acd40591c83926a76380d0", + "reference": "45231191ff59597974acd40591c83926a76380d0", "shasum": "" }, "require": { @@ -175,9 +175,9 @@ "description": "Functional Streams for PHP", "support": { "issues": "https://github.com/phunkie/streams/issues", - "source": "https://github.com/phunkie/streams/tree/1.4.0" + "source": "https://github.com/phunkie/streams/tree/1.5.0" }, - "time": "2026-09-27T10:28:50+00:00" + "time": "2026-10-15T11:01:58+00:00" } ], "packages-dev": [ @@ -4746,5 +4746,5 @@ "php": "^8.2 || ^8.3 || ^8.4" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/src/Client/ResponseBody.php b/src/Client/ResponseBody.php index c98af0f..bab6272 100644 --- a/src/Client/ResponseBody.php +++ b/src/Client/ResponseBody.php @@ -11,14 +11,15 @@ namespace Phunkie\Http4p\Client; +use Phunkie\Streams\Closeable; use Phunkie\Streams\IO\Resource as Source; /** * The body of a response read from the socket as it is pulled: chunked transfer encoding decoded * chunk by chunk, a Content-Length counted down, or everything until the server closes. The socket - * is closed when the body ends. + * is closed when the body ends, and through Closeable when the stream is cut short or throws. */ -final class ResponseBody implements Source +final class ResponseBody implements Source, Closeable { private const CHUNKED = 'chunked'; private const COUNTED = 'counted'; diff --git a/src/Server/PhpServer.php b/src/Server/PhpServer.php index f860df9..4ab98e3 100644 --- a/src/Server/PhpServer.php +++ b/src/Server/PhpServer.php @@ -18,7 +18,6 @@ use Phunkie\Http4p\Response; use Phunkie\Http4p\Route; use Phunkie\Http4p\Router; -use Phunkie\Streams\IO\File\Path; use Phunkie\Types\ImmList; use Throwable; @@ -26,6 +25,7 @@ use function Phunkie\Http4p\Functions\Headers; use function Phunkie\Http4p\Functions\Response; use function Phunkie\Http4p\Functions\StatusInternalServerError; +use function Phunkie\Streams\Functions\io\readHandle; /** * Serves an application through PHP's own SAPI: one request per PHP process, as php-fpm, the @@ -82,7 +82,7 @@ public function handleRequest(): IO } // Get body as Stream - $body = \Stream(new Path('php://input'), 65536); + $body = readHandle(io(fn () => fopen('php://input', 'rb')), 65536); return new Request($method, $uri, Headers($headers), $body); })->flatMap(fn ($request) => ($this->handler)($request))