http-message
http-message copied to clipboard
Set server params for headers in global env
When a ServerRequest is bound to the global environment, we modify $_SERVER when the request method, target and headers are set.
The codeception module now does this itself, but it's not actually his task to do so
/**
* Get additional server params from request.
* @internal It would be nicer if this was solved by Jasny Http Message
*
* @param ServerRequestInterface $psrRequest
* @return array
*/
protected function determineServerParams(ServerRequestInterface $psrRequest)
{
$server = [
'REQUEST_METHOD' => $psrRequest->getMethod(),
'QUERY_STRING' => http_build_query($psrRequest->getQueryParams()),
'REQUEST_URI' => $psrRequest->getRequestTarget()
];
foreach ($psrRequest->getHeaders() as $name => $values) {
$value = end($values);
$key = strtoupper(str_replace('-', '_', $name));
if ($key !== 'CONTENT_TYPE' && $key !== 'CONTENT_LENGTH') {
$key = "HTTP_" . $key;
}
$server[$key] = $value;
}
return $server;
}