xref: /plugin/combo/ComboStrap/Http.php (revision 1fa8c418ed5809db58049141be41b7738471dd32)
1<?php
2
3
4namespace ComboStrap;
5
6
7class Http
8{
9
10    public static function removeHeaderIfPresent(string $key)
11    {
12        foreach (headers_list() as $header) {
13            if (preg_match("/$key/i", $header)) {
14                header_remove($key);
15            }
16        }
17
18    }
19
20    public static function getHeader(string $name)
21    {
22
23        $result = array();
24        foreach (self::getHeaders() as $header) {
25            if (substr($header, 0, strlen($name) + 1) == $name . ':') {
26                $result[] = $header;
27            }
28        }
29
30        return count($result) == 1 ? $result[0] : $result;
31
32    }
33
34    private static function getHeaders(): array
35    {
36        return (function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list());
37    }
38}
39