line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: helper for rendering HTTP status codes for Dancer2 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$Dancer2::Core::HTTP::VERSION = '0.400000'; |
4
|
|
|
|
|
|
|
use strict; |
5
|
145
|
|
|
145
|
|
54410
|
use warnings; |
|
145
|
|
|
|
|
369
|
|
|
145
|
|
|
|
|
3999
|
|
6
|
145
|
|
|
145
|
|
650
|
|
|
145
|
|
|
|
|
283
|
|
|
145
|
|
|
|
|
4232
|
|
7
|
|
|
|
|
|
|
use List::Util qw/ pairmap pairgrep /; |
8
|
145
|
|
|
145
|
|
664
|
|
|
145
|
|
|
|
|
268
|
|
|
145
|
|
|
|
|
77516
|
|
9
|
|
|
|
|
|
|
my $HTTP_CODES = { |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# informational |
12
|
|
|
|
|
|
|
100 => 'Continue', # only on HTTP 1.1 |
13
|
|
|
|
|
|
|
101 => 'Switching Protocols', # only on HTTP 1.1 |
14
|
|
|
|
|
|
|
102 => 'Processing', # WebDAV; RFC 2518 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# processed |
17
|
|
|
|
|
|
|
200 => 'OK', |
18
|
|
|
|
|
|
|
201 => 'Created', |
19
|
|
|
|
|
|
|
202 => 'Accepted', |
20
|
|
|
|
|
|
|
203 => 'Non-Authoritative Information', # only on HTTP 1.1 |
21
|
|
|
|
|
|
|
204 => 'No Content', |
22
|
|
|
|
|
|
|
205 => 'Reset Content', |
23
|
|
|
|
|
|
|
206 => 'Partial Content', |
24
|
|
|
|
|
|
|
207 => 'Multi-Status', # WebDAV; RFC 4918 |
25
|
|
|
|
|
|
|
208 => 'Already Reported', # WebDAV; RFC 5842 |
26
|
|
|
|
|
|
|
# 226 => 'IM Used' # RFC 3229 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# redirections |
29
|
|
|
|
|
|
|
301 => 'Moved Permanently', |
30
|
|
|
|
|
|
|
302 => 'Found', |
31
|
|
|
|
|
|
|
303 => 'See Other', # only on HTTP 1.1 |
32
|
|
|
|
|
|
|
304 => 'Not Modified', |
33
|
|
|
|
|
|
|
305 => 'Use Proxy', # only on HTTP 1.1 |
34
|
|
|
|
|
|
|
306 => 'Switch Proxy', |
35
|
|
|
|
|
|
|
307 => 'Temporary Redirect', # only on HTTP 1.1 |
36
|
|
|
|
|
|
|
# 308 => 'Permanent Redirect' # approved as experimental RFC |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# problems with request |
39
|
|
|
|
|
|
|
400 => 'Bad Request', |
40
|
|
|
|
|
|
|
401 => 'Unauthorized', |
41
|
|
|
|
|
|
|
402 => 'Payment Required', |
42
|
|
|
|
|
|
|
403 => 'Forbidden', |
43
|
|
|
|
|
|
|
404 => 'Not Found', |
44
|
|
|
|
|
|
|
405 => 'Method Not Allowed', |
45
|
|
|
|
|
|
|
406 => 'Not Acceptable', |
46
|
|
|
|
|
|
|
407 => 'Proxy Authentication Required', |
47
|
|
|
|
|
|
|
408 => 'Request Timeout', |
48
|
|
|
|
|
|
|
409 => 'Conflict', |
49
|
|
|
|
|
|
|
410 => 'Gone', |
50
|
|
|
|
|
|
|
411 => 'Length Required', |
51
|
|
|
|
|
|
|
412 => 'Precondition Failed', |
52
|
|
|
|
|
|
|
413 => 'Request Entity Too Large', |
53
|
|
|
|
|
|
|
414 => 'Request-URI Too Long', |
54
|
|
|
|
|
|
|
415 => 'Unsupported Media Type', |
55
|
|
|
|
|
|
|
416 => 'Requested Range Not Satisfiable', |
56
|
|
|
|
|
|
|
417 => 'Expectation Failed', |
57
|
|
|
|
|
|
|
418 => "I'm a teapot", # RFC 2324 |
58
|
|
|
|
|
|
|
# 419 => 'Authentication Timeout', # not in RFC 2616 |
59
|
|
|
|
|
|
|
420 => 'Enhance Your Calm', |
60
|
|
|
|
|
|
|
422 => 'Unprocessable Entity', |
61
|
|
|
|
|
|
|
423 => 'Locked', |
62
|
|
|
|
|
|
|
424 => 'Failed Dependency', # Also used for 'Method Failure' |
63
|
|
|
|
|
|
|
425 => 'Unordered Collection', |
64
|
|
|
|
|
|
|
426 => 'Upgrade Required', |
65
|
|
|
|
|
|
|
428 => 'Precondition Required', |
66
|
|
|
|
|
|
|
429 => 'Too Many Requests', |
67
|
|
|
|
|
|
|
431 => 'Request Header Fields Too Large', |
68
|
|
|
|
|
|
|
444 => 'No Response', |
69
|
|
|
|
|
|
|
449 => 'Retry With', |
70
|
|
|
|
|
|
|
450 => 'Blocked by Windows Parental Controls', |
71
|
|
|
|
|
|
|
451 => 'Unavailable For Legal Reasons', |
72
|
|
|
|
|
|
|
494 => 'Request Header Too Large', |
73
|
|
|
|
|
|
|
495 => 'Cert Error', |
74
|
|
|
|
|
|
|
496 => 'No Cert', |
75
|
|
|
|
|
|
|
497 => 'HTTP to HTTPS', |
76
|
|
|
|
|
|
|
499 => 'Client Closed Request', |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# problems with server |
79
|
|
|
|
|
|
|
500 => 'Internal Server Error', |
80
|
|
|
|
|
|
|
501 => 'Not Implemented', |
81
|
|
|
|
|
|
|
502 => 'Bad Gateway', |
82
|
|
|
|
|
|
|
503 => 'Service Unavailable', |
83
|
|
|
|
|
|
|
504 => 'Gateway Timeout', |
84
|
|
|
|
|
|
|
505 => 'HTTP Version Not Supported', |
85
|
|
|
|
|
|
|
506 => 'Variant Also Negotiates', |
86
|
|
|
|
|
|
|
507 => 'Insufficient Storage', |
87
|
|
|
|
|
|
|
508 => 'Loop Detected', |
88
|
|
|
|
|
|
|
509 => 'Bandwidth Limit Exceeded', |
89
|
|
|
|
|
|
|
510 => 'Not Extended', |
90
|
|
|
|
|
|
|
511 => 'Network Authentication Required', |
91
|
|
|
|
|
|
|
598 => 'Network read timeout error', |
92
|
|
|
|
|
|
|
599 => 'Network connect timeout error', |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$HTTP_CODES = { |
96
|
|
|
|
|
|
|
%$HTTP_CODES, |
97
|
|
|
|
|
|
|
( reverse %$HTTP_CODES ), |
98
|
|
|
|
|
|
|
pairmap { join( '_', split /\W/, lc $a ) => $b } reverse %$HTTP_CODES |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$HTTP_CODES->{error} = $HTTP_CODES->{internal_server_error}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my ( $class, $status ) = @_; |
104
|
|
|
|
|
|
|
return if ! defined $status; |
105
|
778
|
|
|
778
|
1
|
6201
|
return $status if $status =~ /^\d+$/; |
106
|
778
|
100
|
|
|
|
1907
|
if ( exists $HTTP_CODES->{$status} ) { |
107
|
777
|
100
|
|
|
|
12391
|
return $HTTP_CODES->{$status}; |
108
|
7
|
50
|
|
|
|
23
|
} |
109
|
7
|
|
|
|
|
48
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
0
|
|
112
|
|
|
|
|
|
|
my ( $class, $status ) = @_; |
113
|
|
|
|
|
|
|
return if ! defined $status; |
114
|
|
|
|
|
|
|
my $code = $class->status($status); |
115
|
131
|
|
|
131
|
1
|
5214
|
return if ! defined $code || ! exists $HTTP_CODES->{$code}; |
116
|
131
|
100
|
|
|
|
362
|
return $HTTP_CODES->{ $code }; |
117
|
130
|
|
|
|
|
358
|
} |
118
|
130
|
100
|
66
|
|
|
775
|
|
119
|
128
|
|
|
|
|
643
|
pairgrep { $b =~ /^\d+$/ and $a !~ /_/ } %$HTTP_CODES; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my @result = reverse status_mapping(); |
123
|
422
|
100
|
|
422
|
1
|
972
|
return @result; |
|
2
|
|
|
2
|
|
1534
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
1
|
1
|
4
|
1; |
128
|
1
|
|
|
|
|
43
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=pod |
131
|
1
|
|
|
1
|
1
|
693
|
|
132
|
|
|
|
|
|
|
=encoding UTF-8 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 NAME |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Dancer2::Core::HTTP - helper for rendering HTTP status codes for Dancer2 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 VERSION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
version 0.400000 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 FUNCTIONS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 status(status_code) |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Dancer2::Core::HTTP->status(200); # returns 200 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Dancer2::Core::HTTP->status('Not Found'); # returns 404 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Dancer2::Core::HTTP->status('bad_request'); # 400 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns a HTTP status code. If given an integer, it will return the value it |
153
|
|
|
|
|
|
|
received, else it will try to find the appropriate alias and return the correct |
154
|
|
|
|
|
|
|
status. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 status_message(status_code) |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Dancer2::Core::HTTP->status_message(200); # returns 'OK' |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Dancer2::Core::HTTP->status_message('error'); # returns 'Internal Server Error' |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Returns the HTTP status message for the given status code. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 status_mapping() |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my %table = Dancer2::Core::HTTP->status_mapping; |
167
|
|
|
|
|
|
|
# returns ( 'Ok' => 200, 'Created' => 201, ... ) |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns the full table of status -> code mappings. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 code_mapping() |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my %table = Dancer2::Core::HTTP->code_mapping; |
174
|
|
|
|
|
|
|
# returns ( 200 => 'Ok', 201 => 'Created', ... ) |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns the full table of code -> status mappings. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 all_mappings() |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my %table = Dancer2::Core::HTTP->all_mappings; |
181
|
|
|
|
|
|
|
# returns ( 418 => 'I'm a teapot', "I'm a teapot' => 418, 'i_m_a_teapot' => 418 ) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Returns the code-to-status, status-to-code and underscore-groomed status-to-code mappings |
184
|
|
|
|
|
|
|
all mashed up in a single table. Mostly for internal uses. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHOR |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Dancer Core Developers |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This software is copyright (c) 2022 by Alexis Sukrieh. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
195
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |