ServerRequest copies request body to temp stream to allow multiple reads

This commit is contained in:
PJ Dietz 2017-12-18 09:28:11 -05:00
parent 50f1004be5
commit b8b87a8032
2 changed files with 7 additions and 1 deletions

View File

@ -465,7 +465,11 @@ class ServerRequest extends Request implements ServerRequestInterface
*/ */
protected function getStreamForBody() 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);
} }
/** /**

View File

@ -52,7 +52,9 @@ class Stream implements StreamInterface
rewind($this->resource); rewind($this->resource);
} }
$string = $this->getContents(); $string = $this->getContents();
// @codeCoverageIgnoreStart
} catch (\Exception $e) { } catch (\Exception $e) {
// @codeCoverageIgnoreEnd
// Silence exceptions in order to conform with PHP's string casting operations. // Silence exceptions in order to conform with PHP's string casting operations.
} }
return $string; return $string;