line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Method_Allow; |
2
|
1
|
|
|
1
|
|
67618
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
445
|
use parent qw{Plack::Middleware}; |
|
1
|
|
|
|
|
309
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
our $PACKAGE = __PACKAGE__; |
8
|
|
|
|
|
|
|
our %ALLOW = (); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Plack::Middleware::Method_Allow - perl Plack Middleware to filter HTTP Methods |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
builder { |
17
|
|
|
|
|
|
|
enable "Plack::Middleware::Method_Allow", allow=>['GET', 'POST']; |
18
|
|
|
|
|
|
|
$app; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Explicitly allow HTTP methods and return 405 METHOD NOT ALLOWED for all others |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 PROPERTIES |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 allow |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Method that sets the allowed HTTP methods. Must be an array reference of strings. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub allow { |
36
|
11
|
|
|
11
|
1
|
6628
|
my $self = shift; |
37
|
11
|
100
|
|
|
|
42
|
$self->{'allow'} = shift if @_; |
38
|
11
|
100
|
|
|
|
73
|
$self->{'allow'} = [] unless defined $self->{'allow'}; #default is to deny all |
39
|
11
|
100
|
|
|
|
79
|
die("Error: Syntax `enable '$PACKAGE', allow=>['METHOD', ...]`") unless ref($self->{'allow'}) eq 'ARRAY'; |
40
|
4
|
|
|
|
|
20
|
return $self->{'allow'}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 prepare_app |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Method is called once at load to read the allow list. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub prepare_app { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
%ALLOW = map {$_ => 1} @{$self->allow}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 call |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Method is called for each request which return 405 Method Not Allowed for any HTTP method that is not in list. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub call { |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my $env = shift; |
66
|
0
|
0
|
|
|
|
|
if (exists $ALLOW{$env->{'REQUEST_METHOD'}}) { |
67
|
0
|
|
|
|
|
|
return $self->app->($env); |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
return [405 => ['Content-Type' => 'text/plain'] => ['Method Not Allowed']]; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Michael R. Davis |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
MIT License |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright (c) 2022 Michael R. Davis |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |