diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index cf2e5fc23..da914c743 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -457,7 +457,7 @@ if ( * Exit if board is disabled via trigger */ if (($bb_cfg['board_disable'] || file_exists(BB_DISABLED)) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !defined('IN_LOGIN')) { - header('HTTP/1.0 503 Service Unavailable'); + \TorrentPier\Common\Http::statusCode(503); if ($bb_cfg['board_disable']) { // admin lock send_no_cache_headers(); diff --git a/src/Common/Http.php b/src/Common/Http.php new file mode 100644 index 000000000..bb4812ba6 --- /dev/null +++ b/src/Common/Http.php @@ -0,0 +1,54 @@ + 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', + 200 => 'OK', 201 => 'Created', 202 => 'Accepted', + 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', + 206 => 'Partial Content', 207 => 'Multi-Status', 300 => 'Multiple Choices', + 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', + 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', + 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', + 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', + 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', + 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', + 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', + 426 => 'Upgrade Required', 500 => 'Internal Server Error', 501 => 'Not Implemented', + 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', + 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended' + ]; + } + + if ($status_codes[$statusCode] !== null) { + $status_string = $statusCode . ' ' . $status_codes[$statusCode]; + header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status_string, true, $statusCode); + } + } +} diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index 024927b08..4deaf60e5 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -10,6 +10,7 @@ namespace TorrentPier\Legacy; use mysqli_result; +use TorrentPier\Common\Http; /** * Class SqlDb @@ -104,7 +105,7 @@ class SqlDb if (mysqli_connect_error()) { $server = DBG_USER ? $this->cfg['dbhost'] : ''; - header('HTTP/1.0 503 Service Unavailable'); + Http::statusCode(503); bb_log(' ', "db_err/connect_failed_{$this->cfg['dbhost']}"); die("Could not connect to mysql server $server"); }