4 require 5.002; # because we use prototypes
6 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
10 @EXPORT = qw(is_info is_success is_redirect is_error status_message);
11 @EXPORT_OK = qw(is_client_error is_server_error);
14 # Note also addition of mnemonics to @EXPORT below
16 # Unmarked codes are from RFC 2616
17 # See also: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
21 101 => 'Switching Protocols',
22 102 => 'Processing', # RFC 2518 (WebDAV)
26 203 => 'Non-Authoritative Information',
28 205 => 'Reset Content',
29 206 => 'Partial Content',
30 207 => 'Multi-Status', # RFC 2518 (WebDAV)
31 300 => 'Multiple Choices',
32 301 => 'Moved Permanently',
35 304 => 'Not Modified',
37 307 => 'Temporary Redirect',
39 401 => 'Unauthorized',
40 402 => 'Payment Required',
43 405 => 'Method Not Allowed',
44 406 => 'Not Acceptable',
45 407 => 'Proxy Authentication Required',
46 408 => 'Request Timeout',
49 411 => 'Length Required',
50 412 => 'Precondition Failed',
51 413 => 'Request Entity Too Large',
52 414 => 'Request-URI Too Large',
53 415 => 'Unsupported Media Type',
54 416 => 'Request Range Not Satisfiable',
55 417 => 'Expectation Failed',
56 422 => 'Unprocessable Entity', # RFC 2518 (WebDAV)
57 423 => 'Locked', # RFC 2518 (WebDAV)
58 424 => 'Failed Dependency', # RFC 2518 (WebDAV)
59 425 => 'No code', # WebDAV Advanced Collections
60 426 => 'Upgrade Required', # RFC 2817
61 449 => 'Retry with', # unofficial Microsoft
62 500 => 'Internal Server Error',
63 501 => 'Not Implemented',
65 503 => 'Service Unavailable',
66 504 => 'Gateway Timeout',
67 505 => 'HTTP Version Not Supported',
68 506 => 'Variant Also Negotiates', # RFC 2295
69 507 => 'Insufficient Storage', # RFC 2518 (WebDAV)
70 509 => 'Bandwidth Limit Exceeded', # unofficial
71 510 => 'Not Extended', # RFC 2774
74 my $mnemonicCode = '';
76 while (($code, $message) = each %StatusCode) {
77 # create mnemonic subroutines
78 $message =~ tr/a-z \-/A-Z__/;
79 $mnemonicCode .= "sub RC_$message () { $code }\t";
80 # make them exportable
81 $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n";
83 # warn $mnemonicCode; # for development
84 eval $mnemonicCode; # only one eval for speed
87 # backwards compatibility
88 *RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard
89 push(@EXPORT, "RC_MOVED_TEMPORARILY");
92 sub status_message ($) { $StatusCode{$_[0]}; }
94 sub is_info ($) { $_[0] >= 100 && $_[0] < 200; }
95 sub is_success ($) { $_[0] >= 200 && $_[0] < 300; }
96 sub is_redirect ($) { $_[0] >= 300 && $_[0] < 400; }
97 sub is_error ($) { $_[0] >= 400 && $_[0] < 600; }
98 sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; }
99 sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; }
108 HTTP::Status - HTTP Status code processing
115 print status_message($rc), "\n";
118 if (is_success($rc)) { ... }
119 if (is_error($rc)) { ... }
120 if (is_redirect($rc)) { ... }
124 I<HTTP::Status> is a library of routines for defining and
125 classifying HTTP status codes for libwww-perl. Status codes are
126 used to encode the overall outcome of a HTTP response message. Codes
127 correspond to those defined in RFC 2616 and RFC 2518.
131 The following constant functions can be used as mnemonic status code
135 RC_SWITCHING_PROTOCOLS (101)
141 RC_NON_AUTHORITATIVE_INFORMATION (203)
143 RC_RESET_CONTENT (205)
144 RC_PARTIAL_CONTENT (206)
145 RC_MULTI_STATUS (207)
147 RC_MULTIPLE_CHOICES (300)
148 RC_MOVED_PERMANENTLY (301)
151 RC_NOT_MODIFIED (304)
153 RC_TEMPORARY_REDIRECT (307)
156 RC_UNAUTHORIZED (401)
157 RC_PAYMENT_REQUIRED (402)
160 RC_METHOD_NOT_ALLOWED (405)
161 RC_NOT_ACCEPTABLE (406)
162 RC_PROXY_AUTHENTICATION_REQUIRED (407)
163 RC_REQUEST_TIMEOUT (408)
166 RC_LENGTH_REQUIRED (411)
167 RC_PRECONDITION_FAILED (412)
168 RC_REQUEST_ENTITY_TOO_LARGE (413)
169 RC_REQUEST_URI_TOO_LARGE (414)
170 RC_UNSUPPORTED_MEDIA_TYPE (415)
171 RC_REQUEST_RANGE_NOT_SATISFIABLE (416)
172 RC_EXPECTATION_FAILED (417)
173 RC_UNPROCESSABLE_ENTITY (422)
175 RC_FAILED_DEPENDENCY (424)
177 RC_UPGRADE_REQUIRED (426)
180 RC_INTERNAL_SERVER_ERROR (500)
181 RC_NOT_IMPLEMENTED (501)
183 RC_SERVICE_UNAVAILABLE (503)
184 RC_GATEWAY_TIMEOUT (504)
185 RC_HTTP_VERSION_NOT_SUPPORTED (505)
186 RC_VARIANT_ALSO_NEGOTIATES (506)
187 RC_INSUFFICIENT_STORAGE (507)
188 RC_BANDWIDTH_LIMIT_EXCEEDED (509)
189 RC_NOT_EXTENDED (510)
193 The following additional functions are provided. Most of them are
198 =item status_message( $code )
200 The status_message() function will translate status codes to human
201 readable strings. The string is the same as found in the constant
202 names above. If the $code is unknown, then C<undef> is returned.
204 =item is_info( $code )
206 Return TRUE if C<$code> is an I<Informational> status code (1xx). This
207 class of status code indicates a provisional response which can't have
210 =item is_success( $code )
212 Return TRUE if C<$code> is a I<Successful> status code (2xx).
214 =item is_redirect( $code )
216 Return TRUE if C<$code> is a I<Redirection> status code (3xx). This class of
217 status code indicates that further action needs to be taken by the
218 user agent in order to fulfill the request.
220 =item is_error( $code )
222 Return TRUE if C<$code> is an I<Error> status code (4xx or 5xx). The function
223 return TRUE for both client error or a server error status codes.
225 =item is_client_error( $code )
227 Return TRUE if C<$code> is an I<Client Error> status code (4xx). This class
228 of status code is intended for cases in which the client seems to have
231 This function is B<not> exported by default.
233 =item is_server_error( $code )
235 Return TRUE if C<$code> is an I<Server Error> status code (5xx). This class
236 of status codes is intended for cases in which the server is aware
237 that it has erred or is incapable of performing the request.
239 This function is B<not> exported by default.
245 Wished @EXPORT_OK had been used instead of @EXPORT in the beginning.
246 Now too much is exported by default.