line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::HTTPStatusRenderer; |
2
|
1
|
|
|
1
|
|
26876
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
1098
|
use utf8; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1930
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
27333
|
|
|
1
|
|
|
|
|
8
|
|
8
|
|
|
|
|
|
|
# taken from https://metacpan.org/source/GAAS/HTTP-Message-6.06/lib/HTTP/Status.pm |
9
|
|
|
|
|
|
|
my %StatusCode = ( |
10
|
|
|
|
|
|
|
100 => 'Continue', |
11
|
|
|
|
|
|
|
101 => 'Switching Protocols', |
12
|
|
|
|
|
|
|
102 => 'Processing', # RFC 2518 (WebDAV) |
13
|
|
|
|
|
|
|
200 => 'OK', |
14
|
|
|
|
|
|
|
201 => 'Created', |
15
|
|
|
|
|
|
|
202 => 'Accepted', |
16
|
|
|
|
|
|
|
203 => 'Non-Authoritative Information', |
17
|
|
|
|
|
|
|
204 => 'No Content', |
18
|
|
|
|
|
|
|
205 => 'Reset Content', |
19
|
|
|
|
|
|
|
206 => 'Partial Content', |
20
|
|
|
|
|
|
|
207 => 'Multi-Status', # RFC 2518 (WebDAV) |
21
|
|
|
|
|
|
|
208 => 'Already Reported', # RFC 5842 |
22
|
|
|
|
|
|
|
300 => 'Multiple Choices', |
23
|
|
|
|
|
|
|
301 => 'Moved Permanently', |
24
|
|
|
|
|
|
|
302 => 'Found', |
25
|
|
|
|
|
|
|
303 => 'See Other', |
26
|
|
|
|
|
|
|
304 => 'Not Modified', |
27
|
|
|
|
|
|
|
305 => 'Use Proxy', |
28
|
|
|
|
|
|
|
307 => 'Temporary Redirect', |
29
|
|
|
|
|
|
|
400 => 'Bad Request', |
30
|
|
|
|
|
|
|
401 => 'Unauthorized', |
31
|
|
|
|
|
|
|
402 => 'Payment Required', |
32
|
|
|
|
|
|
|
403 => 'Forbidden', |
33
|
|
|
|
|
|
|
404 => 'Not Found', |
34
|
|
|
|
|
|
|
405 => 'Method Not Allowed', |
35
|
|
|
|
|
|
|
406 => 'Not Acceptable', |
36
|
|
|
|
|
|
|
407 => 'Proxy Authentication Required', |
37
|
|
|
|
|
|
|
408 => 'Request Timeout', |
38
|
|
|
|
|
|
|
409 => 'Conflict', |
39
|
|
|
|
|
|
|
410 => 'Gone', |
40
|
|
|
|
|
|
|
411 => 'Length Required', |
41
|
|
|
|
|
|
|
412 => 'Precondition Failed', |
42
|
|
|
|
|
|
|
413 => 'Request Entity Too Large', |
43
|
|
|
|
|
|
|
414 => 'Request-URI Too Large', |
44
|
|
|
|
|
|
|
415 => 'Unsupported Media Type', |
45
|
|
|
|
|
|
|
416 => 'Request Range Not Satisfiable', |
46
|
|
|
|
|
|
|
417 => 'Expectation Failed', |
47
|
|
|
|
|
|
|
418 => 'I\'m a teapot', # RFC 2324 |
48
|
|
|
|
|
|
|
422 => 'Unprocessable Entity', # RFC 2518 (WebDAV) |
49
|
|
|
|
|
|
|
423 => 'Locked', # RFC 2518 (WebDAV) |
50
|
|
|
|
|
|
|
424 => 'Failed Dependency', # RFC 2518 (WebDAV) |
51
|
|
|
|
|
|
|
425 => 'No code', # WebDAV Advanced Collections |
52
|
|
|
|
|
|
|
426 => 'Upgrade Required', # RFC 2817 |
53
|
|
|
|
|
|
|
428 => 'Precondition Required', |
54
|
|
|
|
|
|
|
429 => 'Too Many Requests', |
55
|
|
|
|
|
|
|
431 => 'Request Header Fields Too Large', |
56
|
|
|
|
|
|
|
449 => 'Retry with', # unofficial Microsoft |
57
|
|
|
|
|
|
|
500 => 'Internal Server Error', |
58
|
|
|
|
|
|
|
501 => 'Not Implemented', |
59
|
|
|
|
|
|
|
502 => 'Bad Gateway', |
60
|
|
|
|
|
|
|
503 => 'Service Unavailable', |
61
|
|
|
|
|
|
|
504 => 'Gateway Timeout', |
62
|
|
|
|
|
|
|
505 => 'HTTP Version Not Supported', |
63
|
|
|
|
|
|
|
506 => 'Variant Also Negotiates', # RFC 2295 |
64
|
|
|
|
|
|
|
507 => 'Insufficient Storage', # RFC 2518 (WebDAV) |
65
|
|
|
|
|
|
|
509 => 'Bandwidth Limit Exceeded', # unofficial |
66
|
|
|
|
|
|
|
510 => 'Not Extended', # RFC 2774 |
67
|
|
|
|
|
|
|
511 => 'Network Authentication Required', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
my $template = do {local $/; }; |
70
|
|
|
|
|
|
|
sub register { |
71
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $conf) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $app->routes->any( |
74
|
|
|
|
|
|
|
'/httpstatus/*code' => {code => ''} => \&_httpstatus); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _httpstatus { |
78
|
0
|
|
|
0
|
|
|
my $self = shift; |
79
|
0
|
|
0
|
|
|
|
my $code = $self->param('code')||$self->req->param('code'); |
80
|
0
|
0
|
|
|
|
|
if ( defined $code ) { |
81
|
0
|
|
|
|
|
|
$code =~ s/[^a-zA-Z0-9]+//g; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->stash(sc => \%StatusCode); |
85
|
0
|
|
0
|
|
|
|
$self->stash(pcode => $code // ''); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->render(inline => $template, handler => 'ep'); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Mojolicious::Plugin::HTTPStatusRenderer - HTTP status renderer plugin |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SYNOPSIS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Mojolicious |
100
|
|
|
|
|
|
|
$self->plugin('HTTPStatusRenderer'); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#Mojolicious::Lite |
103
|
|
|
|
|
|
|
plugin 'HTTPStatusRenderer'; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# start daemon, and |
106
|
|
|
|
|
|
|
# access http://:/httpstatus/ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L is a renderer for novice Web Programmer, rawr! |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 OPTIONS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L supports no options |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 register |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $route = $plugin->register(Mojolicious->new); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L, L, L, L, L, L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
turugina Eturugina@cpan.orgE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
136
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__DATA__ |