4 * @see https://github.com/laminas/laminas-diactoros for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
6 * @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
9 declare(strict_types=1);
11 namespace Laminas\Diactoros;
13 use function array_key_exists;
14 use function is_string;
16 use function strtolower;
21 * @param array $server Values obtained from the SAPI (generally `$_SERVER`).
22 * @return array Header/value pairs
24 function marshalHeadersFromSapi(array $server) : array
27 foreach ($server as $key => $value) {
28 if (! is_string($key)) {
36 // Apache prefixes environment variables with REDIRECT_
37 // if they are added by rewrite rules
38 if (strpos($key, 'REDIRECT_') === 0) {
39 $key = substr($key, 9);
41 // We will not overwrite existing variables with the
42 // prefixed versions, though
43 if (array_key_exists($key, $server)) {
48 if (strpos($key, 'HTTP_') === 0) {
49 $name = strtr(strtolower(substr($key, 5)), '_', '-');
50 $headers[$name] = $value;
54 if (strpos($key, 'CONTENT_') === 0) {
55 $name = strtr(strtolower($key), '_', '-');
56 $headers[$name] = $value;