diff --git a/src/Http/Request.php b/src/Http/Request.php index 32acda48..7002f9b0 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -72,6 +72,9 @@ public function __construct(UrlScript $url, $query = NULL, $post = NULL, $files $this->method = $method ?: 'GET'; $this->remoteAddress = $remoteAddress; $this->remoteHost = $remoteHost; + if ($rawBodyCallback !== NULL) { + trigger_error('Nette\Http\Request::__construct(): parameter $rawBodyCallback is deprecated.', E_USER_DEPRECATED); + } $this->rawBodyCallback = $rawBodyCallback; } @@ -287,7 +290,8 @@ public function getRemoteHost() */ public function getRawBody() { - return $this->rawBodyCallback ? call_user_func($this->rawBodyCallback) : NULL; + $body = $this->rawBodyCallback ? call_user_func($this->rawBodyCallback) : file_get_contents('php://input'); + return $body !== '' ? $body : NULL; } diff --git a/src/Http/RequestFactory.php b/src/Http/RequestFactory.php index 3681bafe..09ffade1 100644 --- a/src/Http/RequestFactory.php +++ b/src/Http/RequestFactory.php @@ -210,21 +210,7 @@ public function createHttpRequest() $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; } - // raw body - $rawBodyCallback = function () { - static $rawBody; - - if (PHP_VERSION_ID >= 50600) { - return file_get_contents('php://input'); - - } elseif ($rawBody === NULL) { // can be read only once in PHP < 5.6 - $rawBody = (string) file_get_contents('php://input'); - } - - return $rawBody; - }; - - return new Request($url, NULL, $post, $files, $cookies, $headers, $method, $remoteAddr, $remoteHost, $rawBodyCallback); + return new Request($url, NULL, $post, $files, $cookies, $headers, $method, $remoteAddr, $remoteHost); } } diff --git a/tests/Http/Request.getRawBody.phpt b/tests/Http/Request.getRawBody.phpt index 60e109d0..2a40c5a0 100644 --- a/tests/Http/Request.getRawBody.phpt +++ b/tests/Http/Request.getRawBody.phpt @@ -11,8 +11,9 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; +// compatibility test(function () { - $request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, function () { + @$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, function () { return 'raw body'; });