Mercurial > SimpleWebPresenter
annotate http-response-status-codes.inc @ 43:f42dbf44b661
Beautify file.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 05 Oct 2012 03:16:23 +0200 |
| parents | 9dab5b96b789 |
| children | c6d0892f81ff |
| rev | line source |
|---|---|
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
1 <?php |
|
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
2 /** |
| 43 | 3 * StatusCodes provides named constants for |
| 4 * HTTP protocol status codes. Written for the | |
| 5 * Recess Framework (http://www.recessframework.com/) | |
| 6 * | |
| 7 * @author Kris Jordan | |
| 8 * @license MIT | |
| 9 * @package recess.http | |
| 10 */ | |
| 11 class StatusCodes | |
| 12 { | |
| 13 // [Informational 1xx] | |
| 14 const HTTP_CONTINUE = 100; | |
| 15 const HTTP_SWITCHING_PROTOCOLS = 101; | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
16 |
| 43 | 17 // [Successful 2xx] |
| 18 const HTTP_OK = 200; | |
| 19 const HTTP_CREATED = 201; | |
| 20 const HTTP_ACCEPTED = 202; | |
| 21 const HTTP_NONAUTHORITATIVE_INFORMATION = 203; | |
| 22 const HTTP_NO_CONTENT = 204; | |
| 23 const HTTP_RESET_CONTENT = 205; | |
| 24 const HTTP_PARTIAL_CONTENT = 206; | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
25 |
| 43 | 26 // [Redirection 3xx] |
| 27 const HTTP_MULTIPLE_CHOICES = 300; | |
| 28 const HTTP_MOVED_PERMANENTLY = 301; | |
| 29 const HTTP_FOUND = 302; | |
| 30 const HTTP_SEE_OTHER = 303; | |
| 31 const HTTP_NOT_MODIFIED = 304; | |
| 32 const HTTP_USE_PROXY = 305; | |
| 33 const HTTP_UNUSED= 306; | |
| 34 const HTTP_TEMPORARY_REDIRECT = 307; | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
35 |
| 43 | 36 // [Client Error 4xx] |
| 37 const errorCodesBeginAt = 400; | |
| 38 const HTTP_BAD_REQUEST = 400; | |
| 39 const HTTP_UNAUTHORIZED = 401; | |
| 40 const HTTP_PAYMENT_REQUIRED = 402; | |
| 41 const HTTP_FORBIDDEN = 403; | |
| 42 const HTTP_NOT_FOUND = 404; | |
| 43 const HTTP_METHOD_NOT_ALLOWED = 405; | |
| 44 const HTTP_NOT_ACCEPTABLE = 406; | |
| 45 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; | |
| 46 const HTTP_REQUEST_TIMEOUT = 408; | |
| 47 const HTTP_CONFLICT = 409; | |
| 48 const HTTP_GONE = 410; | |
| 49 const HTTP_LENGTH_REQUIRED = 411; | |
| 50 const HTTP_PRECONDITION_FAILED = 412; | |
| 51 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; | |
| 52 const HTTP_REQUEST_URI_TOO_LONG = 414; | |
| 53 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; | |
| 54 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; | |
| 55 const HTTP_EXPECTATION_FAILED = 417; | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
56 |
| 43 | 57 // [Server Error 5xx] |
| 58 const HTTP_INTERNAL_SERVER_ERROR = 500; | |
| 59 const HTTP_NOT_IMPLEMENTED = 501; | |
| 60 const HTTP_BAD_GATEWAY = 502; | |
| 61 const HTTP_SERVICE_UNAVAILABLE = 503; | |
| 62 const HTTP_GATEWAY_TIMEOUT = 504; | |
| 63 const HTTP_VERSION_NOT_SUPPORTED = 505; | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
64 |
| 43 | 65 private static $messages = |
| 66 array( | |
| 67 // [Informational 1xx] | |
| 68 100=>'100 Continue', | |
| 69 101=>'101 Switching Protocols', | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
70 |
| 43 | 71 // [Successful 2xx] |
| 72 200=>'200 OK', | |
| 73 201=>'201 Created', | |
| 74 202=>'202 Accepted', | |
| 75 203=>'203 Non-Authoritative Information', | |
| 76 204=>'204 No Content', | |
| 77 205=>'205 Reset Content', | |
| 78 206=>'206 Partial Content', | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
79 |
| 43 | 80 // [Redirection 3xx] |
| 81 300=>'300 Multiple Choices', | |
| 82 301=>'301 Moved Permanently', | |
| 83 302=>'302 Found', | |
| 84 303=>'303 See Other', | |
| 85 304=>'304 Not Modified', | |
| 86 305=>'305 Use Proxy', | |
| 87 306=>'306 (Unused)', | |
| 88 307=>'307 Temporary Redirect', | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
89 |
| 43 | 90 // [Client Error 4xx] |
| 91 400=>'400 Bad Request', | |
| 92 401=>'401 Unauthorized', | |
| 93 402=>'402 Payment Required', | |
| 94 403=>'403 Forbidden', | |
| 95 404=>'404 Not Found', | |
| 96 405=>'405 Method Not Allowed', | |
| 97 406=>'406 Not Acceptable', | |
| 98 407=>'407 Proxy Authentication Required', | |
| 99 408=>'408 Request Timeout', | |
| 100 409=>'409 Conflict', | |
| 101 410=>'410 Gone', | |
| 102 411=>'411 Length Required', | |
| 103 412=>'412 Precondition Failed', | |
| 104 413=>'413 Request Entity Too Large', | |
| 105 414=>'414 Request-URI Too Long', | |
| 106 415=>'415 Unsupported Media Type', | |
| 107 416=>'416 Requested Range Not Satisfiable', | |
| 108 417=>'417 Expectation Failed', | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
109 |
| 43 | 110 // [Server Error 5xx] |
| 111 500=>'500 Internal Server Error', | |
| 112 501=>'501 Not Implemented', | |
| 113 502=>'502 Bad Gateway', | |
| 114 503=>'503 Service Unavailable', | |
| 115 504=>'504 Gateway Timeout', | |
| 116 505=>'505 HTTP Version Not Supported' | |
| 117 ); | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
118 |
| 43 | 119 public static function httpHeaderFor($code) |
| 120 { | |
| 121 return 'HTTP/1.1 ' . self::$messages[$code]; | |
| 122 } | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
123 |
| 43 | 124 public static function getMessageForCode($code) |
| 125 { | |
| 126 return self::$messages[$code]; | |
| 127 } | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
128 |
| 43 | 129 public static function isError($code) |
| 130 { | |
| 131 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST; | |
| 132 } | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
133 |
| 43 | 134 public static function canHaveBody($code) |
| 135 { | |
| 136 return | |
| 137 // True if not in 100s | |
| 138 ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK) | |
| 139 && // and not 204 NO CONTENT | |
| 140 $code != self::HTTP_NO_CONTENT | |
| 141 && // and not 304 NOT MODIFIED | |
| 142 $code != self::HTTP_NOT_MODIFIED; | |
| 143 } | |
|
5
18aafb1a8986
Better handling of errors and globals.
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
144 } |
|
13
9dab5b96b789
Clean spurious whitespace.
Tom Fredrik Blenning Klaussen <bfg@blenning.no>
parents:
5
diff
changeset
|
145 ?> |
