Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}


Expand Down
16 changes: 1 addition & 15 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
3 changes: 2 additions & 1 deletion tests/Http/Request.getRawBody.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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';
});

Expand Down