From 0c0f34c7d42ce2a9173d33f39d3426249a0aeec1 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 7 Feb 2018 14:52:21 +0100 Subject: [PATCH] fix: http.core.HttpRequest (now manages both Apache/nginx, especially php-fpm because the function 'getallheaders()' is not available, so gess it from (solution from http://php.net/manual/en/function.getallheaders.php\#84262)) --- build/http/core/HttpRequest.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/build/http/core/HttpRequest.php b/build/http/core/HttpRequest.php index 312a480..f2d919a 100644 --- a/build/http/core/HttpRequest.php +++ b/build/http/core/HttpRequest.php @@ -42,7 +42,7 @@ /* [2] Define headers =========================================================*/ - $this->headers = \getallheaders(); + $this->headers = self::getallheaders_adapter(); /* [3] Define default datasets (GET, POST) @@ -201,4 +201,30 @@ public function HEADERS(){ return $this->headers; } public function METHOD(){ return $this->method; } public function URI(){ return $this->uri; } + + + private static function getallheaders_adapter(){ + /* (1) If exists -> use it + ---------------------------------------------------------*/ + if( function_exists('getallheaders') ) + return getallheaders(); + + /* (2) If does not (php-fpm) + ---------------------------------------------------------*/ + /* (1) init. variables */ + $fetched_headers = []; + + /* (2) Get all headers from $_SERVER */ + foreach($_SERVER as $hname=>$hvalue ){ + + // {1} Store only if begins with 'HTTP_' // + if( substr($hname,0,5) == 'HTTP_' ) + $fetched_headers[ str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($hname,5)))))] = $hvalue; + + } + + /* (3) Return created headers */ + return $fetched_headers; + + } }