1HTTP::Status(3) User Contributed Perl Documentation HTTP::Status(3)
2
3
4
6 HTTP::Status - HTTP Status code processing
7
9 version 6.44
10
12 use HTTP::Status qw(:constants :is status_message);
13
14 if ($rc != HTTP_OK) {
15 print status_message($rc), "\n";
16 }
17
18 if (is_success($rc)) { ... }
19 if (is_error($rc)) { ... }
20 if (is_redirect($rc)) { ... }
21
23 HTTP::Status is a library of routines for defining and classifying HTTP
24 status codes for libwww-perl. Status codes are used to encode the
25 overall outcome of an HTTP response message. Codes correspond to those
26 defined in RFC 2616 and RFC 2518.
27
29 The following constant functions can be used as mnemonic status code
30 names. None of these are exported by default. Use the ":constants"
31 tag to import them all.
32
33 HTTP_CONTINUE (100)
34 HTTP_SWITCHING_PROTOCOLS (101)
35 HTTP_PROCESSING (102)
36 HTTP_EARLY_HINTS (103)
37
38 HTTP_OK (200)
39 HTTP_CREATED (201)
40 HTTP_ACCEPTED (202)
41 HTTP_NON_AUTHORITATIVE_INFORMATION (203)
42 HTTP_NO_CONTENT (204)
43 HTTP_RESET_CONTENT (205)
44 HTTP_PARTIAL_CONTENT (206)
45 HTTP_MULTI_STATUS (207)
46 HTTP_ALREADY_REPORTED (208)
47
48 HTTP_IM_USED (226)
49
50 HTTP_MULTIPLE_CHOICES (300)
51 HTTP_MOVED_PERMANENTLY (301)
52 HTTP_FOUND (302)
53 HTTP_SEE_OTHER (303)
54 HTTP_NOT_MODIFIED (304)
55 HTTP_USE_PROXY (305)
56 HTTP_TEMPORARY_REDIRECT (307)
57 HTTP_PERMANENT_REDIRECT (308)
58
59 HTTP_BAD_REQUEST (400)
60 HTTP_UNAUTHORIZED (401)
61 HTTP_PAYMENT_REQUIRED (402)
62 HTTP_FORBIDDEN (403)
63 HTTP_NOT_FOUND (404)
64 HTTP_METHOD_NOT_ALLOWED (405)
65 HTTP_NOT_ACCEPTABLE (406)
66 HTTP_PROXY_AUTHENTICATION_REQUIRED (407)
67 HTTP_REQUEST_TIMEOUT (408)
68 HTTP_CONFLICT (409)
69 HTTP_GONE (410)
70 HTTP_LENGTH_REQUIRED (411)
71 HTTP_PRECONDITION_FAILED (412)
72 HTTP_PAYLOAD_TOO_LARGE (413)
73 HTTP_URI_TOO_LONG (414)
74 HTTP_UNSUPPORTED_MEDIA_TYPE (415)
75 HTTP_RANGE_NOT_SATISFIABLE (416)
76 HTTP_EXPECTATION_FAILED (417)
77 HTTP_MISDIRECTED REQUEST (421)
78 HTTP_UNPROCESSABLE_ENTITY (422)
79 HTTP_LOCKED (423)
80 HTTP_FAILED_DEPENDENCY (424)
81 HTTP_TOO_EARLY (425)
82 HTTP_UPGRADE_REQUIRED (426)
83 HTTP_PRECONDITION_REQUIRED (428)
84 HTTP_TOO_MANY_REQUESTS (429)
85 HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE (431)
86 HTTP_UNAVAILABLE_FOR_LEGAL_REASONS (451)
87
88 HTTP_INTERNAL_SERVER_ERROR (500)
89 HTTP_NOT_IMPLEMENTED (501)
90 HTTP_BAD_GATEWAY (502)
91 HTTP_SERVICE_UNAVAILABLE (503)
92 HTTP_GATEWAY_TIMEOUT (504)
93 HTTP_HTTP_VERSION_NOT_SUPPORTED (505)
94 HTTP_VARIANT_ALSO_NEGOTIATES (506)
95 HTTP_INSUFFICIENT_STORAGE (507)
96 HTTP_LOOP_DETECTED (508)
97 HTTP_NOT_EXTENDED (510)
98 HTTP_NETWORK_AUTHENTICATION_REQUIRED (511)
99
101 The following additional functions are provided. Most of them are
102 exported by default. The ":is" import tag can be used to import all
103 the classification functions.
104
105 status_message( $code )
106 The status_message() function will translate status codes to human
107 readable strings. The string is the same as found in the constant
108 names above. For example, status_message(303) will return "Not
109 Found".
110
111 If the $code is not registered in the list of IANA HTTP Status
112 Codes <https://www.iana.org/assignments/http-status-codes/http-
113 status-codes.xhtml> then "undef" is returned.
114
115 status_constant_name( $code )
116 The status_constant_name() function will translate a status code to
117 a string which has the name of the constant for that status code.
118 For example, status_constant_name(404) will return
119 "HTTP_NOT_FOUND".
120
121 If the $code is not registered in the list of IANA HTTP Status
122 Codes <https://www.iana.org/assignments/http-status-codes/http-
123 status-codes.xhtml> then "undef" is returned.
124
125 is_info( $code )
126 Return TRUE if $code is an Informational status code (1xx). This
127 class of status code indicates a provisional response which can't
128 have any content.
129
130 is_success( $code )
131 Return TRUE if $code is a Successful status code (2xx).
132
133 is_redirect( $code )
134 Return TRUE if $code is a Redirection status code (3xx). This class
135 of status code indicates that further action needs to be taken by
136 the user agent in order to fulfill the request.
137
138 is_error( $code )
139 Return TRUE if $code is an Error status code (4xx or 5xx). The
140 function returns TRUE for both client and server error status
141 codes.
142
143 is_client_error( $code )
144 Return TRUE if $code is a Client Error status code (4xx). This
145 class of status code is intended for cases in which the client
146 seems to have erred.
147
148 This function is not exported by default.
149
150 is_server_error( $code )
151 Return TRUE if $code is a Server Error status code (5xx). This
152 class of status codes is intended for cases in which the server is
153 aware that it has erred or is incapable of performing the request.
154
155 This function is not exported by default.
156
157 is_cacheable_by_default( $code )
158 Return TRUE if $code indicates that a response is cacheable by
159 default, and it can be reused by a cache with heuristic expiration.
160 All other status codes are not cacheable by default. See RFC 7231 -
161 HTTP/1.1 Semantics and Content, Section 6.1. Overview of Status
162 Codes <https://tools.ietf.org/html/rfc7231#section-6.1>.
163
164 This function is not exported by default.
165
167 IANA HTTP Status Codes <https://www.iana.org/assignments/http-status-
168 codes/http-status-codes.xhtml>
169
171 For legacy reasons all the "HTTP_" constants are exported by default
172 with the prefix "RC_". It's recommended to use explicit imports and
173 the ":constants" tag instead of relying on this.
174
176 Gisle Aas <gisle@activestate.com>
177
179 This software is copyright (c) 1994 by Gisle Aas.
180
181 This is free software; you can redistribute it and/or modify it under
182 the same terms as the Perl 5 programming language system itself.
183
184
185
186perl v5.38.0 2023-07-20 HTTP::Status(3)