Mercurial > SimpleWebPresenter
comparison http-response-status-codes.inc @ 48:c6d0892f81ff
Documentation.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 09 Oct 2012 20:05:12 +0200 |
| parents | f42dbf44b661 |
| children | 6cb775b62281 |
comparison
equal
deleted
inserted
replaced
| 47:66382989353f | 48:c6d0892f81ff |
|---|---|
| 3 * StatusCodes provides named constants for | 3 * StatusCodes provides named constants for |
| 4 * HTTP protocol status codes. Written for the | 4 * HTTP protocol status codes. Written for the |
| 5 * Recess Framework (http://www.recessframework.com/) | 5 * Recess Framework (http://www.recessframework.com/) |
| 6 * | 6 * |
| 7 * @author Kris Jordan | 7 * @author Kris Jordan |
| 8 * @license MIT | 8 * @author Tom Fredrik Blenning Klaussen |
| 9 * @package recess.http | 9 * @copyright MIT |
| 10 */ | 10 */ |
| 11 class StatusCodes | 11 class StatusCodes |
| 12 { | 12 { |
| 13 // [Informational 1xx] | 13 // [Informational 1xx] |
| 14 /** | |
| 15 * <a href="http://httpstatus.es/100">HTTP_CONTINUE</a> | |
| 16 */ | |
| 14 const HTTP_CONTINUE = 100; | 17 const HTTP_CONTINUE = 100; |
| 18 /** | |
| 19 * <a href="http://httpstatus.es/101">HTTP_SWITCHING_PROTOCOLS</a> | |
| 20 */ | |
| 15 const HTTP_SWITCHING_PROTOCOLS = 101; | 21 const HTTP_SWITCHING_PROTOCOLS = 101; |
| 16 | 22 |
| 17 // [Successful 2xx] | 23 // [Successful 2xx] |
| 24 /** | |
| 25 * <a href="http://httpstatus.es/200">HTTP_OK</a> | |
| 26 */ | |
| 18 const HTTP_OK = 200; | 27 const HTTP_OK = 200; |
| 28 /** | |
| 29 * <a href="http://httpstatus.es/201">HTTP_CREATED</a> | |
| 30 */ | |
| 19 const HTTP_CREATED = 201; | 31 const HTTP_CREATED = 201; |
| 32 /** | |
| 33 * <a href="http://httpstatus.es/202">HTTP_ACCEPTED</a> | |
| 34 */ | |
| 20 const HTTP_ACCEPTED = 202; | 35 const HTTP_ACCEPTED = 202; |
| 36 /** | |
| 37 * <a href="http://httpstatus.es/203">HTTP_ACCEPTED</a> | |
| 38 */ | |
| 21 const HTTP_NONAUTHORITATIVE_INFORMATION = 203; | 39 const HTTP_NONAUTHORITATIVE_INFORMATION = 203; |
| 40 /** | |
| 41 * <a href="http://httpstatus.es/204">HTTP_NO_CONTENT</a> | |
| 42 */ | |
| 22 const HTTP_NO_CONTENT = 204; | 43 const HTTP_NO_CONTENT = 204; |
| 44 /** | |
| 45 * <a href="http://httpstatus.es/205">HTTP_RESET_CONTENT</a> | |
| 46 */ | |
| 23 const HTTP_RESET_CONTENT = 205; | 47 const HTTP_RESET_CONTENT = 205; |
| 48 /** | |
| 49 * <a href="http://httpstatus.es/206">HTTP_PARTIAL_CONTENT</a> | |
| 50 */ | |
| 24 const HTTP_PARTIAL_CONTENT = 206; | 51 const HTTP_PARTIAL_CONTENT = 206; |
| 25 | 52 |
| 26 // [Redirection 3xx] | 53 // [Redirection 3xx] |
| 54 /** | |
| 55 * <a href="http://httpstatus.es/300">HTTP_MULTIPLE_CHOICES</a> | |
| 56 */ | |
| 27 const HTTP_MULTIPLE_CHOICES = 300; | 57 const HTTP_MULTIPLE_CHOICES = 300; |
| 58 /** | |
| 59 * <a href="http://httpstatus.es/301">HTTP_MOVED_PERMANENTLY</a> | |
| 60 */ | |
| 28 const HTTP_MOVED_PERMANENTLY = 301; | 61 const HTTP_MOVED_PERMANENTLY = 301; |
| 62 /** | |
| 63 * <a href="http://httpstatus.es/302">HTTP_FOUND</a> | |
| 64 */ | |
| 29 const HTTP_FOUND = 302; | 65 const HTTP_FOUND = 302; |
| 66 /** | |
| 67 * <a href="http://httpstatus.es/303">HTTP_SEE_OTHER</a> | |
| 68 */ | |
| 30 const HTTP_SEE_OTHER = 303; | 69 const HTTP_SEE_OTHER = 303; |
| 70 /** | |
| 71 * <a href="http://httpstatus.es/304">HTTP_NOT_MODIFIED</a> | |
| 72 */ | |
| 31 const HTTP_NOT_MODIFIED = 304; | 73 const HTTP_NOT_MODIFIED = 304; |
| 74 /** | |
| 75 * <a href="http://httpstatus.es/305">HTTP_USE_PROXY</a> | |
| 76 */ | |
| 32 const HTTP_USE_PROXY = 305; | 77 const HTTP_USE_PROXY = 305; |
| 33 const HTTP_UNUSED= 306; | 78 /** |
| 79 * <a href="http://httpstatus.es/306">HTTP_UNUSED</a> | |
| 80 */ | |
| 81 const HTTP_UNUSED = 306; | |
| 82 /** | |
| 83 * <a href="http://httpstatus.es/307">HTTP_TEMPORARY_REDIRECT</a> | |
| 84 */ | |
| 34 const HTTP_TEMPORARY_REDIRECT = 307; | 85 const HTTP_TEMPORARY_REDIRECT = 307; |
| 35 | 86 |
| 36 // [Client Error 4xx] | 87 // [Client Error 4xx] |
| 37 const errorCodesBeginAt = 400; | 88 /** |
| 89 * Defines the beginning of errorCodes | |
| 90 */ | |
| 91 private const errorCodesBeginAt = 400; | |
| 92 /** | |
| 93 * <a href="http://httpstatus.es/400">HTTP_BAD_REQUEST</a> | |
| 94 */ | |
| 38 const HTTP_BAD_REQUEST = 400; | 95 const HTTP_BAD_REQUEST = 400; |
| 96 /** | |
| 97 * <a href="http://httpstatus.es/401">HTTP_UNAUTHORIZED</a> | |
| 98 */ | |
| 39 const HTTP_UNAUTHORIZED = 401; | 99 const HTTP_UNAUTHORIZED = 401; |
| 100 /** | |
| 101 * <a href="http://httpstatus.es/402">HTTP_PAYMENT_REQUIRED</a> | |
| 102 */ | |
| 40 const HTTP_PAYMENT_REQUIRED = 402; | 103 const HTTP_PAYMENT_REQUIRED = 402; |
| 104 /** | |
| 105 * <a href="http://httpstatus.es/403">HTTP_FORBIDDEN</a> | |
| 106 */ | |
| 41 const HTTP_FORBIDDEN = 403; | 107 const HTTP_FORBIDDEN = 403; |
| 108 /** | |
| 109 * <a href="http://httpstatus.es/404">HTTP_NOT_FOUND</a> | |
| 110 */ | |
| 42 const HTTP_NOT_FOUND = 404; | 111 const HTTP_NOT_FOUND = 404; |
| 112 /** | |
| 113 * <a href="http://httpstatus.es/405">HTTP_METHOD_NOT_ALLOWED</a> | |
| 114 */ | |
| 43 const HTTP_METHOD_NOT_ALLOWED = 405; | 115 const HTTP_METHOD_NOT_ALLOWED = 405; |
| 116 /** | |
| 117 * <a href="http://httpstatus.es/406">HTTP_NOT_ACCEPTABLE</a> | |
| 118 */ | |
| 44 const HTTP_NOT_ACCEPTABLE = 406; | 119 const HTTP_NOT_ACCEPTABLE = 406; |
| 120 /** | |
| 121 * <a href="http://httpstatus.es/407">HTTP_PROXY_AUTHENTICATION_REQUIRED</a> | |
| 122 */ | |
| 45 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; | 123 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; |
| 124 /** | |
| 125 * <a href="http://httpstatus.es/408">HTTP_REQUEST_TIMEOUT</a> | |
| 126 */ | |
| 46 const HTTP_REQUEST_TIMEOUT = 408; | 127 const HTTP_REQUEST_TIMEOUT = 408; |
| 128 /** | |
| 129 * <a href="http://httpstatus.es/409">HTTP_CONFLICT</a> | |
| 130 */ | |
| 47 const HTTP_CONFLICT = 409; | 131 const HTTP_CONFLICT = 409; |
| 132 /** | |
| 133 * <a href="http://httpstatus.es/410">HTTP_GONE</a> | |
| 134 */ | |
| 48 const HTTP_GONE = 410; | 135 const HTTP_GONE = 410; |
| 136 /** | |
| 137 * <a href="http://httpstatus.es/411">HTTP_LENGTH_REQUIRED</a> | |
| 138 */ | |
| 49 const HTTP_LENGTH_REQUIRED = 411; | 139 const HTTP_LENGTH_REQUIRED = 411; |
| 140 /** | |
| 141 * <a href="http://httpstatus.es/412">HTTP_PRECONDITION_FAILED</a> | |
| 142 */ | |
| 50 const HTTP_PRECONDITION_FAILED = 412; | 143 const HTTP_PRECONDITION_FAILED = 412; |
| 144 /** | |
| 145 * <a href="http://httpstatus.es/413">HTTP_REQUEST_ENTITY_TOO_LARGE</a> | |
| 146 */ | |
| 51 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; | 147 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; |
| 148 /** | |
| 149 * <a href="http://httpstatus.es/414">HTTP_REQUEST_URI_TOO_LONG</a> | |
| 150 */ | |
| 52 const HTTP_REQUEST_URI_TOO_LONG = 414; | 151 const HTTP_REQUEST_URI_TOO_LONG = 414; |
| 152 /** | |
| 153 * <a href="http://httpstatus.es/415">HTTP_UNSUPPORTED_MEDIA_TYPE</a> | |
| 154 */ | |
| 53 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; | 155 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; |
| 156 /** | |
| 157 * <a href="http://httpstatus.es/416">HTTP_REQUESTED_RANGE_NOT_SATISFIABLE</a> | |
| 158 */ | |
| 54 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; | 159 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; |
| 160 /** | |
| 161 * <a href="http://httpstatus.es/417">HTTP_EXPECTATION_FAILED</a> | |
| 162 */ | |
| 55 const HTTP_EXPECTATION_FAILED = 417; | 163 const HTTP_EXPECTATION_FAILED = 417; |
| 56 | 164 |
| 57 // [Server Error 5xx] | 165 // [Server Error 5xx] |
| 166 /** | |
| 167 * <a href="http://httpstatus.es/500">HTTP_INTERNAL_SERVER_ERROR</a> | |
| 168 */ | |
| 58 const HTTP_INTERNAL_SERVER_ERROR = 500; | 169 const HTTP_INTERNAL_SERVER_ERROR = 500; |
| 170 /** | |
| 171 * <a href="http://httpstatus.es/501">HTTP_NOT_IMPLEMENTED</a> | |
| 172 */ | |
| 59 const HTTP_NOT_IMPLEMENTED = 501; | 173 const HTTP_NOT_IMPLEMENTED = 501; |
| 174 /** | |
| 175 * <a href="http://httpstatus.es/502">HTTP_BAD_GATEWAY</a> | |
| 176 */ | |
| 60 const HTTP_BAD_GATEWAY = 502; | 177 const HTTP_BAD_GATEWAY = 502; |
| 178 /** | |
| 179 * <a href="http://httpstatus.es/503">HTTP_SERVICE_UNAVAILABLE</a> | |
| 180 */ | |
| 61 const HTTP_SERVICE_UNAVAILABLE = 503; | 181 const HTTP_SERVICE_UNAVAILABLE = 503; |
| 182 /** | |
| 183 * <a href="http://httpstatus.es/504">HTTP_GATEWAY_TIMEOUT</a> | |
| 184 */ | |
| 62 const HTTP_GATEWAY_TIMEOUT = 504; | 185 const HTTP_GATEWAY_TIMEOUT = 504; |
| 186 /** | |
| 187 * <a href="http://httpstatus.es/505">HTTP_VERSION_NOT_SUPPORTED</a> | |
| 188 */ | |
| 63 const HTTP_VERSION_NOT_SUPPORTED = 505; | 189 const HTTP_VERSION_NOT_SUPPORTED = 505; |
| 64 | 190 |
| 65 private static $messages = | 191 private static $messages = |
| 66 array( | 192 array( |
| 67 // [Informational 1xx] | 193 // [Informational 1xx] |
| 114 503=>'503 Service Unavailable', | 240 503=>'503 Service Unavailable', |
| 115 504=>'504 Gateway Timeout', | 241 504=>'504 Gateway Timeout', |
| 116 505=>'505 HTTP Version Not Supported' | 242 505=>'505 HTTP Version Not Supported' |
| 117 ); | 243 ); |
| 118 | 244 |
| 245 /** | |
| 246 * Get the header for the specified code. | |
| 247 * | |
| 248 * @param $code Http status code | |
| 249 * @return A textual representation of the header | |
| 250 */ | |
| 119 public static function httpHeaderFor($code) | 251 public static function httpHeaderFor($code) |
| 120 { | 252 { |
| 121 return 'HTTP/1.1 ' . self::$messages[$code]; | 253 return 'HTTP/1.1 ' . self::$messages[$code]; |
| 122 } | 254 } |
| 123 | 255 |
| 256 /** | |
| 257 * Get a canonical status message for the specified code | |
| 258 * | |
| 259 * @param $code Http status code | |
| 260 * @return Text for the specified code | |
| 261 */ | |
| 124 public static function getMessageForCode($code) | 262 public static function getMessageForCode($code) |
| 125 { | 263 { |
| 126 return self::$messages[$code]; | 264 return self::$messages[$code]; |
| 127 } | 265 } |
| 128 | 266 |
| 267 /** | |
| 268 * Checks if the specified code is an error code. | |
| 269 * | |
| 270 * @param $code Http status code | |
| 271 * @return bool Answer | |
| 272 */ | |
| 129 public static function isError($code) | 273 public static function isError($code) |
| 130 { | 274 { |
| 131 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST; | 275 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST; |
| 132 } | 276 } |
| 133 | 277 |
| 278 /** | |
| 279 * Can the specified status code have a body? | |
| 280 * | |
| 281 * @param $code Http status code | |
| 282 * @return bool Answer | |
| 283 */ | |
| 134 public static function canHaveBody($code) | 284 public static function canHaveBody($code) |
| 135 { | 285 { |
| 136 return | 286 return |
| 137 // True if not in 100s | 287 // True if not in 100s |
| 138 ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK) | 288 ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK) |
