Skip to content

Commit

Permalink
fix(Request): adds header parsing for NGINX context
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsasharegan committed Mar 14, 2018
1 parent dd31946 commit 0e4828d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Request.php
Expand Up @@ -87,8 +87,10 @@ function __construct() {
$this->URIComponents = parse_url($_SERVER['REQUEST_URI']);
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
$this->ip = $_SERVER['REMOTE_ADDR'];
$this->headers = getallheaders();
if (!$this->headers) $this->headers = [];
$this->headers = Request::parseHeaders();
if (!$this->headers) {
$this->headers = [];
}

switch (strtolower($this->contentType)) {
case strtolower(stristr($this->contentType, Http::MIME_APPLICATION_JSON)):
Expand Down Expand Up @@ -333,4 +335,25 @@ public function __toString() {
return json_encode($this);
}

public static function parseHeaders() {
if (!function_exists('getallheaders')) {
function getallheaders() {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[
str_replace(' ', '-', ucwords(
strtolower(
str_replace('_', ' ', substr($name, 5))
)
))
] = $value;
}
}
}
}

return getallheaders();
}

}

0 comments on commit 0e4828d

Please sign in to comment.