line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::EmulateOPTIONS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: handle OPTIONS requests as HEAD |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
2634
|
use v5.14; |
|
4
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
115
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
22
|
use parent 'Plack::Middleware'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
24
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
279
|
use Plack::Util; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
128
|
|
12
|
4
|
|
|
4
|
|
29
|
use Plack::Util::Accessor qw/ filter callback /; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
32
|
|
13
|
4
|
|
|
4
|
|
257
|
use HTTP::Status (); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
1238
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 'v0.3.1'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub prepare_app { |
19
|
4
|
|
|
4
|
1
|
521
|
my ($self) = @_; |
20
|
|
|
|
|
|
|
|
21
|
4
|
100
|
|
|
|
15
|
unless (defined $self->callback) { |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->callback( sub { |
24
|
3
|
|
|
3
|
|
38
|
my ($res) = @_; |
25
|
3
|
|
|
|
|
15
|
Plack::Util::header_set( $res->[1], 'allow', "GET, HEAD, OPTIONS" ); |
26
|
3
|
|
|
|
|
142
|
}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub call { |
32
|
27
|
|
|
27
|
1
|
179234
|
my ( $self, $env ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
27
|
|
|
|
|
110
|
my $filter = $self->filter; |
35
|
27
|
|
|
|
|
184
|
my $callback = $self->callback; |
36
|
|
|
|
|
|
|
|
37
|
27
|
100
|
100
|
|
|
220
|
if ( $env->{REQUEST_METHOD} eq "OPTIONS" && ( !$filter || $filter->($env) ) ) { |
|
|
|
100
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
9
|
|
|
|
|
155
|
my $res = $self->app->( { %$env, REQUEST_METHOD => "HEAD" } ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return Plack::Util::response_cb( |
42
|
|
|
|
|
|
|
$res, |
43
|
|
|
|
|
|
|
sub { |
44
|
9
|
|
|
9
|
|
167
|
my ($res) = @_; |
45
|
9
|
100
|
|
|
|
40
|
if ( HTTP::Status::is_success($res->[0]) ) { |
46
|
5
|
|
|
|
|
55
|
$callback->( $res, $env ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
9
|
|
|
|
|
1698
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
|
54
|
18
|
|
|
|
|
82
|
return $self->app->($env); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |