25use InvalidArgumentException;
35 private static $headersSentCallback =
null;
38 $old = self::$headersSentCallback;
39 self::$headersSentCallback = $callback;
51 static $statusMessage = [
53 101 =>
'Switching Protocols',
58 203 =>
'Non-Authoritative Information',
60 205 =>
'Reset Content',
61 206 =>
'Partial Content',
62 207 =>
'Multi-Status',
63 300 =>
'Multiple Choices',
64 301 =>
'Moved Permanently',
67 304 =>
'Not Modified',
69 307 =>
'Temporary Redirect',
71 401 =>
'Unauthorized',
72 402 =>
'Payment Required',
75 405 =>
'Method Not Allowed',
76 406 =>
'Not Acceptable',
77 407 =>
'Proxy Authentication Required',
78 408 =>
'Request Timeout',
81 411 =>
'Length Required',
82 412 =>
'Precondition Failed',
83 413 =>
'Request Entity Too Large',
84 414 =>
'Request-URI Too Large',
85 415 =>
'Unsupported Media Type',
86 416 =>
'Request Range Not Satisfiable',
87 417 =>
'Expectation Failed',
88 422 =>
'Unprocessable Entity',
90 424 =>
'Failed Dependency',
91 428 =>
'Precondition Required',
92 429 =>
'Too Many Requests',
93 431 =>
'Request Header Fields Too Large',
94 500 =>
'Internal Server Error',
95 501 =>
'Not Implemented',
97 503 =>
'Service Unavailable',
98 504 =>
'Gateway Timeout',
99 505 =>
'HTTP Version Not Supported',
100 507 =>
'Insufficient Storage',
101 511 =>
'Network Authentication Required',
103 return $statusMessage[$code] ??
null;
114 static $version = null;
115 $message = self::getMessage( $code );
116 if ( $message ===
null ) {
117 throw new InvalidArgumentException(
"Unknown HTTP status code $code" );
120 if ( $version ===
null ) {
121 $version = isset( $_SERVER[
'SERVER_PROTOCOL'] ) &&
122 $_SERVER[
'SERVER_PROTOCOL'] ===
'HTTP/1.0' ?
127 return "HTTP/$version $code $message";
137 if ( headers_sent() ) {
138 if ( self::$headersSentCallback ) {
139 ( self::$headersSentCallback )();
148 header( self::getHeader( $code ) );
149 }
catch ( InvalidArgumentException $ex ) {
150 trigger_error(
"Unknown HTTP status code $code", E_USER_WARNING );
157class_alias( HttpStatus::class,
'HttpStatus' );