3 * @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
8 namespace Zend\Diactoros;
10 use function array_key_exists;
12 use function strtolower;
17 * @param array $server Values obtained from the SAPI (generally `$_SERVER`).
18 * @return array Header/value pairs
20 function marshalHeadersFromSapi(array $server)
23 foreach ($server as $key => $value) {
24 // Apache prefixes environment variables with REDIRECT_
25 // if they are added by rewrite rules
26 if (strpos($key, 'REDIRECT_') === 0) {
27 $key = substr($key, 9);
29 // We will not overwrite existing variables with the
30 // prefixed versions, though
31 if (array_key_exists($key, $server)) {
36 if ($value && strpos($key, 'HTTP_') === 0) {
37 $name = strtr(strtolower(substr($key, 5)), '_', '-');
38 $headers[$name] = $value;
42 if ($value && strpos($key, 'CONTENT_') === 0) {
43 $name = 'content-' . strtolower(substr($key, 8));
44 $headers[$name] = $value;