Skip to content

Commit

Permalink
Fix subsequent reads from php://input in ServerRequest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sagikazarmark committed Dec 7, 2018
1 parent 610233d commit d3dfe3d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d3dfe3d

Please sign in to comment.