X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2FHttpStatus.php;h=72fc33386935716ec0b7afaaaf4f55de15dd9e16;hp=809bfdf5a8ca531609de19aa7f3a6ed4d29d13cc;hb=e3bd13db0c285f312e31bb1b7271af4628cca80c;hpb=a8b5e408bf8df6a02d18c70ad22ec14f2333abd4 diff --git a/includes/libs/HttpStatus.php b/includes/libs/HttpStatus.php index 809bfdf5a8..72fc333869 100644 --- a/includes/libs/HttpStatus.php +++ b/includes/libs/HttpStatus.php @@ -26,14 +26,13 @@ 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( + static $statusMessage = [ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', @@ -84,8 +83,32 @@ class HttpStatus { 505 => 'HTTP Version Not Supported', 507 => 'Insufficient Storage', 511 => 'Network Authentication Required', - ); + ]; 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" ); + } + }