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
|
|
2593
|
use v5.10; |
|
4
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
80
|
|
8
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
103
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
20
|
use parent 'Plack::Middleware'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
22
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
279
|
use Plack::Util; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
136
|
|
13
|
4
|
|
|
4
|
|
32
|
use Plack::Util::Accessor qw/ filter callback /; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
33
|
|
14
|
4
|
|
|
4
|
|
271
|
use HTTP::Status (); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1215
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 'v0.2.2'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub prepare_app { |
20
|
4
|
|
|
4
|
1
|
511
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
4
|
100
|
|
|
|
15
|
unless (defined $self->callback) { |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$self->callback( sub { |
25
|
3
|
|
|
3
|
|
8
|
my ($res) = @_; |
26
|
3
|
|
|
|
|
48
|
Plack::Util::header_set( $res->[1], 'allow', "GET, HEAD, OPTIONS" ); |
27
|
3
|
|
|
|
|
172
|
}); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub call { |
33
|
27
|
|
|
27
|
1
|
182636
|
my ( $self, $env ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
27
|
|
|
|
|
100
|
my $filter = $self->filter; |
36
|
27
|
|
|
|
|
186
|
my $callback = $self->callback; |
37
|
|
|
|
|
|
|
|
38
|
27
|
100
|
100
|
|
|
200
|
if ( $env->{REQUEST_METHOD} eq "OPTIONS" && ( !$filter || $filter->($env) ) ) { |
|
|
|
100
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
9
|
|
|
|
|
144
|
my $res = $self->app->( { %$env, REQUEST_METHOD => "HEAD" } ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return Plack::Util::response_cb( |
43
|
|
|
|
|
|
|
$res, |
44
|
|
|
|
|
|
|
sub { |
45
|
9
|
|
|
9
|
|
175
|
my ($res) = @_; |
46
|
9
|
100
|
|
|
|
40
|
if ( HTTP::Status::is_success($res->[0]) ) { |
47
|
5
|
|
|
|
|
47
|
$callback->( $res, $env ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
9
|
|
|
|
|
1633
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
|
|
|
|
|
|
|
55
|
18
|
|
|
|
|
76
|
return $self->app->($env); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |