Author: Sara Golemon (sgolemon)
Date: 2021-07-05T13:25:11Z

Commit: 
https://github.com/php/web-php/commit/3707f9a7c493df2465f645f70952a7495ccb57a1
Raw diff: 
https://github.com/php/web-php/commit/3707f9a7c493df2465f645f70952a7495ccb57a1.diff

Update status_header() helper function

Changed paths:
  M  include/errors.inc


Diff:

diff --git a/include/errors.inc b/include/errors.inc
index f143ff2fb..793d08750 100644
--- a/include/errors.inc
+++ b/include/errors.inc
@@ -88,34 +88,26 @@ function error_nomirror($mirror) {
 }
 
 // Send out a proper status header
-function status_header($num)
+function status_header(int $status): bool
 {
-    // Set status text
-    switch ($num) {
-        case 200: $status = "OK"; break;
-        case 301: $status = "Moved Permanently"; break;
-        case 302: $status = "Found"; break;
-        case 404: $status = "Not Found"; break;
-        default: return FALSE;
-    }
+       $text = [
+               200 => 'OK',
+               301 => 'Moved Permanently',
+               302 => 'Found',
+               404 => 'Not Found',
+       ];
+       if (!isset($text[$status])) {
+               return false;
+       }
 
-    // Figure out HTTP protocol version - use 1.1 answer for 1.1 request,
-    // answer with HTTP/1.0 for any other (ancient or futuristic) user
-    switch (strtoupper($_SERVER['SERVER_PROTOCOL'])) {
-        case 'HTTP/1.0':
-            @header("HTTP/1.0 $num $status");
-            break;
-
-        case 'HTTP/1.1':
-        default:
-            @header("HTTP/1.1 $num $status");
-            break;
-    }
+       // Only respond with HTTP/1.0 for a 1.0 request specifically.
+       // Respond with 1.1 for anything else.
+       $proto = strcasecmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/1.0') ? '1.1' : 
'1.0';
 
-    // BC code for PHP < 4.3.0
-    @header("Status: $num $status", TRUE, $num);
+       @header("HTTP/$proto $status {$text[$status]}");
+    @header("Status: $status {$text[$status]}", true, $status);
 
-    return TRUE;
+    return true;
 }
 
 /******************************************************************************

-- 
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to