diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /includes/libs/HttpStatus.php | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'includes/libs/HttpStatus.php')
-rw-r--r-- | includes/libs/HttpStatus.php | 28 |
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" ); + } + } |