Skip to content

Commit 3707f9a

Browse files
committed
Update status_header() helper function
1 parent f5737af commit 3707f9a

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

include/errors.inc

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,26 @@ function error_nomirror($mirror) {
8888
}
8989

9090
// Send out a proper status header
91-
function status_header($num)
91+
function status_header(int $status): bool
9292
{
93-
// Set status text
94-
switch ($num) {
95-
case 200: $status = "OK"; break;
96-
case 301: $status = "Moved Permanently"; break;
97-
case 302: $status = "Found"; break;
98-
case 404: $status = "Not Found"; break;
99-
default: return FALSE;
100-
}
93+
$text = [
94+
200 => 'OK',
95+
301 => 'Moved Permanently',
96+
302 => 'Found',
97+
404 => 'Not Found',
98+
];
99+
if (!isset($text[$status])) {
100+
return false;
101+
}
101102

102-
// Figure out HTTP protocol version - use 1.1 answer for 1.1 request,
103-
// answer with HTTP/1.0 for any other (ancient or futuristic) user
104-
switch (strtoupper($_SERVER['SERVER_PROTOCOL'])) {
105-
case 'HTTP/1.0':
106-
@header("HTTP/1.0 $num $status");
107-
break;
108-
109-
case 'HTTP/1.1':
110-
default:
111-
@header("HTTP/1.1 $num $status");
112-
break;
113-
}
103+
// Only respond with HTTP/1.0 for a 1.0 request specifically.
104+
// Respond with 1.1 for anything else.
105+
$proto = strcasecmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/1.0') ? '1.1' : '1.0';
114106

115-
// BC code for PHP < 4.3.0
116-
@header("Status: $num $status", TRUE, $num);
107+
@header("HTTP/$proto $status {$text[$status]}");
108+
@header("Status: $status {$text[$status]}", true, $status);
117109

118-
return TRUE;
110+
return true;
119111
}
120112

121113
/******************************************************************************

0 commit comments

Comments
 (0)