From 703536d2bf31e7eda6d3c16a5f5a5d0198a6d68c Mon Sep 17 00:00:00 2001 From: Daniel Stelljes Date: Mon, 29 Sep 2014 21:55:40 -0500 Subject: [PATCH 1/2] Set up request body caching --- flight/net/Request.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/flight/net/Request.php b/flight/net/Request.php index 628c4f3..c2142e1 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -120,6 +120,11 @@ class Request { */ public $proxy_ip; + /** + * @var mixed Data from the request body + */ + protected static $body; + /** * Constructor. * @@ -198,13 +203,18 @@ class Request { */ public static function getBody() { + if (!is_null(self::$body)) { + return self::$body; + } + + $body = ''; $method = self::getMethod(); if ($method == 'POST' || $method == 'PUT') { - return file_get_contents('php://input'); + $body = file_get_contents('php://input'); } - return ''; + return self::$body = $body; } /** From 54440d1db0e2abd74a705ec5926a75572fed62fb Mon Sep 17 00:00:00 2001 From: Daniel Stelljes Date: Wed, 1 Oct 2014 19:46:03 -0500 Subject: [PATCH 2/2] Removed static body variable from Request --- flight/net/Request.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/flight/net/Request.php b/flight/net/Request.php index c2142e1..e9dac8e 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -120,11 +120,6 @@ class Request { */ public $proxy_ip; - /** - * @var mixed Data from the request body - */ - protected static $body; - /** * Constructor. * @@ -201,20 +196,20 @@ class Request { * * @return string Raw HTTP request body */ - public static function getBody() - { - if (!is_null(self::$body)) { - return self::$body; + public static function getBody() { + static $body; + + if (!is_null($body)) { + return $body; } - $body = ''; $method = self::getMethod(); if ($method == 'POST' || $method == 'PUT') { $body = file_get_contents('php://input'); } - return self::$body = $body; + return $body; } /**