Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Scrutinize
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed Jan 26, 2017
1 parent eebdc0e commit 4527b44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions src/ServerRequest/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ trait Headers
*/
abstract public function getServerParams();


/**
* Turn a server parameter key to a header name
*
* @param string $key
* @return string|null
*/
protected function serverParamKeyToHeaderName($key)
{
$name = null;

if (\Jasny\str_starts_with($key, 'HTTP_')) {
$name = $this->headerCase(substr($key, 5));
} elseif (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
$name = $this->headerCase($key);
}

return $name;
}

/**
* Determine the headers based on the server parameters
Expand All @@ -30,19 +49,12 @@ protected function determineHeaders()
$params = $this->getServerParams();
$headers = [];

foreach ($params as $param => $value) {
if (!is_string($value)) {
continue;
}
if (\Jasny\str_starts_with($param, 'HTTP_')) {
$key = $this->headerCase(substr($param, 5));
} elseif (in_array($param, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) {
$key = $this->headerCase($param);
} else {
continue;
}
foreach ($params as $key => $value) {
$name = $this->serverParamKeyToHeaderName($key);

$headers[$key] = [$value];
if (isset($name) && is_string($value)) {
$headers[$name] = [$value];
}
}

return $headers;
Expand Down
2 changes: 1 addition & 1 deletion src/ServerRequest/ParsedBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait ParsedBody

/**
* The condition under which the body was parsed
* @var array|null
* @var array|false|null
*/
protected $parseCondition;

Expand Down

0 comments on commit 4527b44

Please sign in to comment.