Skip to content

Commit 373ea43

Browse files
Grinnzoalders
authored andcommitted
Fix HTTP status messages to match RFC7231 and IANA registry
- backcompat constants added for old names - added backcompat HTTP_NO_CODE constant that was previously missed - added tests for all renamed constants
1 parent 191a836 commit 373ea43

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

lib/HTTP/Status.pm

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ my %StatusCode = (
3333
207 => 'Multi-Status', # RFC 4918: WebDAV
3434
208 => 'Already Reported', # RFC 5842: WebDAV bindings
3535
# 209 .. 225
36-
226 => 'IM used', # RFC 3229: Delta encoding
36+
226 => 'IM Used', # RFC 3229: Delta encoding
3737
# 227 .. 299
3838
300 => 'Multiple Choices',
3939
301 => 'Moved Permanently',
@@ -57,10 +57,10 @@ my %StatusCode = (
5757
410 => 'Gone',
5858
411 => 'Length Required',
5959
412 => 'Precondition Failed', # RFC 7232: Conditional Request
60-
413 => 'Request Entity Too Large',
61-
414 => 'Request-URI Too Large',
60+
413 => 'Payload Too Large',
61+
414 => 'URI Too Long',
6262
415 => 'Unsupported Media Type',
63-
416 => 'Request Range Not Satisfiable', # RFC 7233: Range Requests
63+
416 => 'Range Not Satisfiable', # RFC 7233: Range Requests
6464
417 => 'Expectation Failed',
6565
# 418 .. 420
6666
421 => 'Misdirected Request', # RFC 7540: HTTP/2
@@ -118,9 +118,30 @@ die if $@;
118118
*RC_MOVED_TEMPORARILY = \&RC_FOUND; # 302 was renamed in the standard
119119
push(@EXPORT, "RC_MOVED_TEMPORARILY");
120120

121+
*RC_REQUEST_ENTITY_TOO_LARGE = \&RC_PAYLOAD_TOO_LARGE;
122+
push(@EXPORT, "RC_REQUEST_ENTITY_TOO_LARGE");
123+
124+
*RC_REQUEST_URI_TOO_LARGE = \&RC_URI_TOO_LONG;
125+
push(@EXPORT, "RC_REQUEST_URI_TOO_LARGE");
126+
127+
*RC_REQUEST_RANGE_NOT_SATISFIABLE = \&RC_RANGE_NOT_SATISFIABLE;
128+
push(@EXPORT, "RC_REQUEST_RANGE_NOT_SATISFIABLE");
129+
121130
*RC_NO_CODE = \&RC_UNORDERED_COLLECTION;
122131
push(@EXPORT, "RC_NO_CODE");
123132

133+
*HTTP_REQUEST_ENTITY_TOO_LARGE = \&HTTP_PAYLOAD_TOO_LARGE;
134+
push(@EXPORT_OK, "HTTP_REQUEST_ENTITY_TOO_LARGE");
135+
136+
*HTTP_REQUEST_URI_TOO_LARGE = \&HTTP_URI_TOO_LONG;
137+
push(@EXPORT_OK, "HTTP_REQUEST_URI_TOO_LARGE");
138+
139+
*HTTP_REQUEST_RANGE_NOT_SATISFIABLE = \&HTTP_RANGE_NOT_SATISFIABLE;
140+
push(@EXPORT_OK, "HTTP_REQUEST_RANGE_NOT_SATISFIABLE");
141+
142+
*HTTP_NO_CODE = \&HTTP_UNORDERED_COLLECTION;
143+
push(@EXPORT_OK, "HTTP_NO_CODE");
144+
124145
our %EXPORT_TAGS = (
125146
constants => [grep /^HTTP_/, @EXPORT_OK],
126147
is => [grep /^is_/, @EXPORT, @EXPORT_OK],
@@ -221,10 +242,10 @@ tag to import them all.
221242
HTTP_GONE (410)
222243
HTTP_LENGTH_REQUIRED (411)
223244
HTTP_PRECONDITION_FAILED (412)
224-
HTTP_REQUEST_ENTITY_TOO_LARGE (413)
225-
HTTP_REQUEST_URI_TOO_LARGE (414)
245+
HTTP_PAYLOAD_TOO_LARGE (413)
246+
HTTP_URI_TOO_LONG (414)
226247
HTTP_UNSUPPORTED_MEDIA_TYPE (415)
227-
HTTP_REQUEST_RANGE_NOT_SATISFIABLE (416)
248+
HTTP_RANGE_NOT_SATISFIABLE (416)
228249
HTTP_EXPECTATION_FAILED (417)
229250
HTTP_MISDIRECTED REQUEST (421)
230251
HTTP_UNPROCESSABLE_ENTITY (422)

t/status.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use strict;
22
use warnings;
33

44
use Test::More;
5-
plan tests => 39;
5+
plan tests => 47;
66

77
use HTTP::Status qw(:constants :is status_message);
88

@@ -15,6 +15,16 @@ ok(is_client_error(HTTP_I_AM_A_TEAPOT));
1515
ok(is_redirect(HTTP_MOVED_PERMANENTLY));
1616
ok(is_redirect(HTTP_PERMANENT_REDIRECT));
1717

18+
# renamed status constants
19+
ok(is_error(HTTP_REQUEST_ENTITY_TOO_LARGE));
20+
ok(is_error(HTTP_PAYLOAD_TOO_LARGE));
21+
ok(is_error(HTTP_REQUEST_URI_TOO_LARGE));
22+
ok(is_error(HTTP_URI_TOO_LONG));
23+
ok(is_error(HTTP_REQUEST_RANGE_NOT_SATISFIABLE));
24+
ok(is_error(HTTP_RANGE_NOT_SATISFIABLE));
25+
ok(is_error(HTTP_NO_CODE));
26+
ok(is_error(HTTP_UNORDERED_COLLECTION));
27+
1828
ok(!is_success(HTTP_NOT_FOUND));
1929

2030
is(status_message( 0), undef);

0 commit comments

Comments
 (0)