From 107893525694f84baa0ad1be6a4ea67590617406 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 17 Feb 2018 18:51:53 +0100 Subject: [PATCH] +fix apache => nginx (getallheaders function) does not exist anymore --- build/http/core/HttpRequest.php | 38 ++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/build/http/core/HttpRequest.php b/build/http/core/HttpRequest.php index de3a294..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) @@ -57,7 +57,10 @@ $this->body = \file_get_contents('php://input'); /* (2) Fetch content type */ - $this->type = self::getContentType($this->headers['Content-Type']); + if( isset($this->headers['Content-Type']) ) + $this->type = self::getContentType($this->headers['Content-Type']); + else + $this->type = self::getContentType(); /* [5] Parse BODY data -> POST @@ -78,7 +81,10 @@ /* [1] Checks argv =========================================================*/ if( is_null($pContentType) ) - $pContentType = $_SERVER['CONTENT_TYPE']; + if( isset($_SERVER['CONTENT_TYPE']) ) + $pContentType = $_SERVER['CONTENT_TYPE']; + else + $pContentType = 'text/plain'; /* [2] Checks types @@ -195,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; + + } }