aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/PicoFarad/Response.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/PicoFarad/Response.php')
-rw-r--r--inc/3rdparty/PicoFarad/Response.php156
1 files changed, 156 insertions, 0 deletions
diff --git a/inc/3rdparty/PicoFarad/Response.php b/inc/3rdparty/PicoFarad/Response.php
new file mode 100644
index 00000000..9114fde0
--- /dev/null
+++ b/inc/3rdparty/PicoFarad/Response.php
@@ -0,0 +1,156 @@
1<?php
2
3namespace PicoFarad\Response;
4
5
6function force_download($filename)
7{
8 header('Content-Disposition: attachment; filename="'.$filename.'"');
9}
10
11
12function content_type($mimetype)
13{
14 header('Content-Type: '.$mimetype);
15}
16
17
18function status($status_code)
19{
20 $sapi_name = php_sapi_name();
21
22 if (strpos($sapi_name, 'apache') !== false || $sapi_name === 'cli-server') {
23 header('HTTP/1.0 '.$status_code);
24 }
25 else {
26 header('Status: '.$status_code);
27 }
28}
29
30
31function redirect($url)
32{
33 header('Location: '.$url);
34 exit;
35}
36
37
38function json(array $data, $status_code = 200)
39{
40 status($status_code);
41
42 header('Content-Type: application/json');
43 echo json_encode($data);
44
45 exit;
46}
47
48
49function text($data, $status_code = 200)
50{
51 status($status_code);
52
53 header('Content-Type: text/plain; charset=utf-8');
54 echo $data;
55
56 exit;
57}
58
59
60function html($data, $status_code = 200)
61{
62 status($status_code);
63
64 header('Content-Type: text/html; charset=utf-8');
65 echo $data;
66
67 exit;
68}
69
70
71function xml($data, $status_code = 200)
72{
73 status($status_code);
74
75 header('Content-Type: text/xml; charset=utf-8');
76 echo $data;
77
78 exit;
79}
80
81
82function js($data, $status_code = 200)
83{
84 status($status_code);
85
86 header('Content-Type: text/javascript; charset=utf-8');
87 echo $data;
88
89 exit;
90}
91
92
93function binary($data, $status_code = 200)
94{
95 status($status_code);
96
97 header('Content-Transfer-Encoding: binary');
98 header('Content-Type: application/octet-stream');
99 echo $data;
100
101 exit;
102}
103
104
105function csp(array $policies = array())
106{
107 $policies['default-src'] = "'self'";
108 $values = '';
109
110 foreach ($policies as $policy => $hosts) {
111
112 if (is_array($hosts)) {
113
114 $acl = '';
115
116 foreach ($hosts as &$host) {
117
118 if ($host === '*' || $host === 'self' || strpos($host, 'http') === 0) {
119 $acl .= $host.' ';
120 }
121 }
122 }
123 else {
124
125 $acl = $hosts;
126 }
127
128 $values .= $policy.' '.trim($acl).'; ';
129 }
130
131 header('Content-Security-Policy: '.$values);
132}
133
134
135function nosniff()
136{
137 header('X-Content-Type-Options: nosniff');
138}
139
140
141function xss()
142{
143 header('X-XSS-Protection: 1; mode=block');
144}
145
146
147function hsts()
148{
149 header('Strict-Transport-Security: max-age=31536000');
150}
151
152
153function xframe($mode = 'DENY', array $urls = array())
154{
155 header('X-Frame-Options: '.$mode.' '.implode(' ', $urls));
156} \ No newline at end of file