summaryrefslogtreecommitdiff
path: root/includes/libs/HttpStatus.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/libs/HttpStatus.php')
-rw-r--r--includes/libs/HttpStatus.php28
1 files changed, 24 insertions, 4 deletions
diff --git a/includes/libs/HttpStatus.php b/includes/libs/HttpStatus.php
index 809bfdf5..442298a6 100644
--- a/includes/libs/HttpStatus.php
+++ b/includes/libs/HttpStatus.php
@@ -26,11 +26,10 @@
class HttpStatus {
/**
- * Get the message associated with HTTP response code $code
+ * Get the message associated with an HTTP response status code
*
- * @param $code Integer: status code
- * @return String or null: message or null if $code is not in the list of
- * messages
+ * @param int $code Status code
+ * @return string|null Message, or null if $code is not known
*/
public static function getMessage( $code ) {
static $statusMessage = array(
@@ -88,4 +87,25 @@ class HttpStatus {
return isset( $statusMessage[$code] ) ? $statusMessage[$code] : null;
}
+ /**
+ * Output an HTTP status code header
+ *
+ * @since 1.26
+ * @param int $code Status code
+ */
+ public static function header( $code ) {
+ static $version = null;
+ $message = self::getMessage( $code );
+ if ( $message === null ) {
+ trigger_error( "Unknown HTTP status code $code", E_USER_WARNING );
+ return false;
+ }
+
+ if ( $version === null ) {
+ $version = isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.0' ? '1.0' : '1.1';
+ }
+
+ header( "HTTP/$version $code $message" );
+ }
+
}