Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This copies the php://input stream to a php://temp stream that can be rewound and read multiple times so that the raw request body is not cannabilised by the first middleware to read it. Also automatically rewinds the request body after reading it in Request::getMethod() on POST so the “first” call to getContents() within the App invocation is not empty. Should resolve #1386
- Loading branch information
Showing
6 changed files
with
393 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Slim Framework (http://slimframework.com) | ||
* | ||
* @link https://github.com/codeguy/Slim | ||
* @copyright Copyright (c) 2011-2015 Josh Lockhart | ||
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License) | ||
*/ | ||
namespace Slim\Http; | ||
|
||
/** | ||
* Provides a PSR-7 implementation of a reusable raw request body | ||
*/ | ||
class RequestBody extends Body | ||
{ | ||
/** | ||
* Create a new RequestBody. | ||
*/ | ||
public function __construct() | ||
{ | ||
$stream = fopen('php://temp', 'w+'); | ||
stream_copy_to_stream(fopen('php://input', 'r'), $stream); | ||
rewind($stream); | ||
|
||
parent::__construct($stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.