Skip to content

Commit 906d85f

Browse files
waterkipoalders
authored andcommitted
Update several status codes to RFC 9110
* 306 is officially reserved but unused * 413 is called 'Content Too Large' in RFC 9110 * 418 is officially reserved, so let's make it official here too * 422 is imported from WebDAV and named 'Unprocessable Content'. Reference: https://www.rfc-editor.org/rfc/rfc9110.html#name-changes-from-rfc-7231 Signed-off-by: Wesley Schwengle <[email protected]>
1 parent aa059cf commit 906d85f

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

lib/HTTP/Status.pm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ my %StatusCode = (
4040
303 => 'See Other',
4141
304 => 'Not Modified', # RFC 7232: Conditional Request
4242
305 => 'Use Proxy',
43+
306 => '(Unused)', # RFC 9110: Previously used and reserved
4344
307 => 'Temporary Redirect',
4445
308 => 'Permanent Redirect', # RFC 7528: Permanent Redirect
4546
# 309 .. 399
@@ -56,14 +57,15 @@ my %StatusCode = (
5657
410 => 'Gone',
5758
411 => 'Length Required',
5859
412 => 'Precondition Failed', # RFC 7232: Conditional Request
59-
413 => 'Payload Too Large',
60+
413 => 'Content Too Large',
6061
414 => 'URI Too Long',
6162
415 => 'Unsupported Media Type',
6263
416 => 'Range Not Satisfiable', # RFC 7233: Range Requests
6364
417 => 'Expectation Failed',
64-
# 418 .. 420
65+
418 => "I'm a teapot", # RFC 2324: RFC9110 reserved it
66+
# 419 .. 420
6567
421 => 'Misdirected Request', # RFC 7540: HTTP/2
66-
422 => 'Unprocessable Entity', # RFC 4918: WebDAV
68+
422 => 'Unprocessable Content', # RFC 9110: WebDAV
6769
423 => 'Locked', # RFC 4918: WebDAV
6870
424 => 'Failed Dependency', # RFC 4918: WebDAV
6971
425 => 'Too Early', # RFC 8470: Using Early Data in HTTP
@@ -88,21 +90,17 @@ my %StatusCode = (
8890
# 509
8991
510 => 'Not Extended', # RFC 2774: Extension Framework
9092
511 => 'Network Authentication Required', # RFC 6585: Additional Codes
91-
);
92-
93-
my %StatusCodeName;
9493

95-
# keep some unofficial codes that used to be in this distribution
96-
%StatusCode = (
97-
%StatusCode,
98-
418 => 'I\'m a teapot', # RFC 2324: HTCPC/1.0 1-april
94+
# Keep some unofficial codes that used to be in this distribution
9995
449 => 'Retry with', # microsoft
10096
509 => 'Bandwidth Limit Exceeded', # Apache / cPanel
10197
);
10298

99+
my %StatusCodeName;
103100
my $mnemonicCode = '';
104101
my ($code, $message);
105102
while (($code, $message) = each %StatusCode) {
103+
next if $message eq '(Unused)';
106104
# create mnemonic subroutines
107105
$message =~ s/I'm/I am/;
108106
$message =~ tr/a-z \-/A-Z__/;
@@ -121,7 +119,9 @@ die if $@;
121119
push(@EXPORT, "RC_MOVED_TEMPORARILY");
122120

123121
my %compat = (
124-
REQUEST_ENTITY_TOO_LARGE => \&HTTP_PAYLOAD_TOO_LARGE,
122+
UNPROCESSABLE_ENTITY => \&HTTP_UNPROCESSABLE_CONTENT,
123+
PAYLOAD_TOO_LARGE => \&HTTP_CONTENT_TOO_LARGE,
124+
REQUEST_ENTITY_TOO_LARGE => \&HTTP_CONTENT_TOO_LARGE,
125125
REQUEST_URI_TOO_LARGE => \&HTTP_URI_TOO_LONG,
126126
REQUEST_RANGE_NOT_SATISFIABLE => \&HTTP_RANGE_NOT_SATISFIABLE,
127127
NO_CODE => \&HTTP_TOO_EARLY,
@@ -242,13 +242,13 @@ tag to import them all.
242242
HTTP_GONE (410)
243243
HTTP_LENGTH_REQUIRED (411)
244244
HTTP_PRECONDITION_FAILED (412)
245-
HTTP_PAYLOAD_TOO_LARGE (413)
245+
HTTP_CONTENT_TOO_LARGE (413)
246246
HTTP_URI_TOO_LONG (414)
247247
HTTP_UNSUPPORTED_MEDIA_TYPE (415)
248248
HTTP_RANGE_NOT_SATISFIABLE (416)
249249
HTTP_EXPECTATION_FAILED (417)
250250
HTTP_MISDIRECTED REQUEST (421)
251-
HTTP_UNPROCESSABLE_ENTITY (422)
251+
HTTP_UNPROCESSABLE_CONTENT (422)
252252
HTTP_LOCKED (423)
253253
HTTP_FAILED_DEPENDENCY (424)
254254
HTTP_TOO_EARLY (425)

t/status.t

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use strict;
22
use warnings;
33

44
use Test::More;
5-
plan tests => 53;
65

76
use HTTP::Status qw(:constants :is status_message status_constant_name status_codes);
87

@@ -11,7 +10,6 @@ is(HTTP_OK, 200);
1110
ok(is_info(HTTP_CONTINUE));
1211
ok(is_success(HTTP_ACCEPTED));
1312
ok(is_error(HTTP_BAD_REQUEST));
14-
ok(is_client_error(HTTP_I_AM_A_TEAPOT));
1513
ok(is_redirect(HTTP_MOVED_PERMANENTLY));
1614
ok(is_redirect(HTTP_PERMANENT_REDIRECT));
1715

@@ -25,6 +23,13 @@ ok(is_error(HTTP_RANGE_NOT_SATISFIABLE));
2523
ok(is_error(HTTP_NO_CODE));
2624
ok(is_error(HTTP_UNORDERED_COLLECTION));
2725
ok(is_error(HTTP_TOO_EARLY));
26+
ok(is_error(HTTP_UNPROCESSABLE_ENTITY));
27+
ok(is_error(HTTP_PAYLOAD_TOO_LARGE));
28+
29+
# Have a sip and a great day
30+
ok(is_client_error(HTTP_I_AM_A_TEAPOT));
31+
ok(is_error(HTTP_I_AM_A_TEAPOT));
32+
is(status_message(418), "I'm a teapot");
2833

2934
ok(!is_success(HTTP_NOT_FOUND));
3035

@@ -59,3 +64,5 @@ is(status_constant_name(999), undef);
5964

6065
my %status_codes = status_codes();
6166
is($status_codes{200}, status_message(200));
67+
68+
done_testing;

0 commit comments

Comments
 (0)