From d3dfe3dae9282d133c46c7280b30a787ab4c0898 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 7 Dec 2018 13:00:23 +0100 Subject: [PATCH] Fix subsequent reads from php://input in ServerRequest According to the PHP documentation reading from the same php://input stream is not possible. Even reading from separate streams is SAPI dependent. http://php.net/manual/de/wrappers.php.php#wrappers.php.input This change adds a CachingStream wrapping the default stream when using ServerRequest::fromGlobals to allow subsequent reads. --- src/ServerRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 99f453a5..1a09a6c8 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -168,7 +168,7 @@ public static function fromGlobals() $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; $headers = getallheaders(); $uri = self::getUriFromGlobals(); - $body = new LazyOpenStream('php://input', 'r+'); + $body = new CachingStream(new LazyOpenStream('php://input', 'r+')); $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1'; $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);