More adjusted API tests
[dokuwiki.git] / inc / HTTP / Headers.php
blob254eb1ca8ed3bb7daa6e51b8f0281a7609ce40c5
1 <?php
3 namespace dokuwiki\HTTP;
5 /**
6 * Utilities to send HTTP Headers
7 */
8 class Headers
10 /**
11 * Send a Content-Security-Polica Header
13 * Expects an associative array with individual policies and their values
15 * @param array $policy
17 public static function contentSecurityPolicy($policy)
19 foreach ($policy as $key => $values) {
20 // if the value is not an array, we also accept newline terminated strings
21 if (!is_array($values)) $values = explode("\n", $values);
22 $values = array_map('trim', $values);
23 $values = array_unique($values);
24 $values = array_filter($values);
25 $policy[$key] = $values;
28 $cspheader = 'Content-Security-Policy:';
29 foreach ($policy as $key => $values) {
30 if ($values) {
31 $cspheader .= " $key " . implode(' ', $values) . ';';
32 } else {
33 $cspheader .= " $key;";
37 header($cspheader);