From b8b87a803251429c428d55cd2fc1fdb9f42829e2 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Mon, 18 Dec 2017 09:28:11 -0500 Subject: [PATCH] ServerRequest copies request body to temp stream to allow multiple reads --- src/Message/ServerRequest.php | 6 +++++- src/Message/Stream.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index a46ed1f..4329901 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -465,7 +465,11 @@ class ServerRequest extends Request implements ServerRequestInterface */ protected function getStreamForBody() { - return new Stream(fopen("php://input", "r")); + $input = fopen("php://input", "rb"); + $temp = fopen("php://temp", "wb+"); + stream_copy_to_stream($input, $temp); + rewind($temp); + return new Stream($temp); } /** diff --git a/src/Message/Stream.php b/src/Message/Stream.php index 1491bd6..61be3b1 100644 --- a/src/Message/Stream.php +++ b/src/Message/Stream.php @@ -52,7 +52,9 @@ class Stream implements StreamInterface rewind($this->resource); } $string = $this->getContents(); + // @codeCoverageIgnoreStart } catch (\Exception $e) { + // @codeCoverageIgnoreEnd // Silence exceptions in order to conform with PHP's string casting operations. } return $string;