]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/PicoFarad/Response.php
3 namespace PicoFarad\Response
;
6 function force_download($filename)
8 header('Content-Disposition: attachment; filename="'.$filename.'"');
12 function content_type($mimetype)
14 header('Content-Type: '.$mimetype);
18 function status($status_code)
20 $sapi_name = php_sapi_name();
22 if (strpos($sapi_name, 'apache') !== false || $sapi_name === 'cli-server') {
23 header('HTTP/1.0 '.$status_code);
26 header('Status: '.$status_code);
31 function redirect($url)
33 header('Location: '.$url);
38 function json(array $data, $status_code = 200)
42 header('Content-Type: application/json');
43 echo json_encode($data);
49 function text($data, $status_code = 200)
53 header('Content-Type: text/plain; charset=utf-8');
60 function html($data, $status_code = 200)
64 header('Content-Type: text/html; charset=utf-8');
71 function xml($data, $status_code = 200)
75 header('Content-Type: text/xml; charset=utf-8');
82 function js($data, $status_code = 200)
86 header('Content-Type: text/javascript; charset=utf-8');
93 function binary($data, $status_code = 200)
97 header('Content-Transfer-Encoding: binary');
98 header('Content-Type: application/octet-stream');
105 function csp(array $policies = array())
107 $policies['default-src'] = "'self'";
110 foreach ($policies as $policy => $hosts) {
112 if (is_array($hosts)) {
116 foreach ($hosts as &$host) {
118 if ($host === '*' || $host === 'self' || strpos($host, 'http') === 0) {
128 $values .= $policy.' '.trim($acl).'; ';
131 header('Content-Security-Policy: '.$values);
137 header('X-Content-Type-Options: nosniff');
143 header('X-XSS-Protection: 1; mode=block');
149 header('Strict-Transport-Security: max-age=31536000');
153 function xframe($mode = 'DENY', array $urls = array())
155 header('X-Frame-Options: '.$mode.' '.implode(' ', $urls));