line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MethodOverride; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
26001
|
use 5.010; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
198
|
|
4
|
5
|
|
|
5
|
|
636
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
5
|
|
|
|
|
9410
|
|
|
5
|
|
|
|
|
28
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1578
|
use Scalar::Util qw(weaken); |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
2039
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.053'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
4
|
|
|
4
|
1
|
149
|
my ($self, $app, $conf) = @_; |
12
|
|
|
|
|
|
|
|
13
|
4
|
100
|
|
|
|
14
|
my $header = |
14
|
|
|
|
|
|
|
exists $conf->{header} ? $conf->{header} : 'X-HTTP-Method-Override'; |
15
|
4
|
100
|
|
|
|
12
|
my $param = exists $conf->{param} ? $conf->{param} : undef; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$app->hook( |
18
|
|
|
|
|
|
|
after_build_tx => sub { |
19
|
39
|
|
|
39
|
|
245992
|
my $tx = shift; |
20
|
|
|
|
|
|
|
|
21
|
39
|
|
|
|
|
113
|
weaken $tx; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$tx->req->content->on(body => sub { |
24
|
39
|
|
|
|
|
19793
|
my $req = $tx->req; |
25
|
|
|
|
|
|
|
|
26
|
39
|
100
|
|
|
|
226
|
return unless $req->method eq 'POST'; |
27
|
|
|
|
|
|
|
|
28
|
35
|
|
100
|
|
|
295
|
my $method = defined $header && $req->headers->header($header); |
29
|
|
|
|
|
|
|
|
30
|
35
|
100
|
|
|
|
331
|
if ($method) { |
|
|
100
|
|
|
|
|
|
31
|
8
|
|
|
|
|
13
|
$req->headers->remove($header); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (defined $param) { |
34
|
21
|
|
|
|
|
50
|
$method = $req->url->query->clone->param($param); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
35
|
100
|
66
|
|
|
2448
|
if ($method and $method =~ /^[A-Za-z]+$/) { |
38
|
21
|
|
66
|
|
|
66
|
$app->log->debug(($header // $param) . ': ' . $method); |
39
|
21
|
|
|
|
|
618
|
$req->method($method); |
40
|
|
|
|
|
|
|
} |
41
|
39
|
|
|
|
|
104
|
}); |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
32
|
); |
44
|
|
|
|
|
|
|
|
45
|
4
|
100
|
|
|
|
68
|
if (defined $param) { |
46
|
|
|
|
|
|
|
$app->hook(before_dispatch => sub { |
47
|
25
|
|
|
25
|
|
9145
|
shift->req->url->query->remove($param); |
48
|
3
|
|
|
|
|
12
|
}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |