line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::Middleware::MethodOverride; |
2
|
1
|
|
|
1
|
|
463
|
use HTTP::Engine::Middleware; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has 'HTTP_METHODS' => ( |
5
|
|
|
|
|
|
|
is => 'rw', |
6
|
|
|
|
|
|
|
isa => 'ArrayRef', |
7
|
|
|
|
|
|
|
default => sub { |
8
|
|
|
|
|
|
|
return [ 'GET', 'HEAD', 'PUT', 'POST', 'DELETE' ]; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'METHOD_OVERRIDE_PARAM_KEY' => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
isa => 'Str', |
15
|
|
|
|
|
|
|
default => '_method', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'HTTP_METHOD_OVERRIDE_HEADER' => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Str', |
21
|
|
|
|
|
|
|
default => 'X-HTTP-Method-Override', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
before_handle { |
25
|
|
|
|
|
|
|
my ( $c, $self, $req ) = @_; |
26
|
|
|
|
|
|
|
$self->override_request_method($req); |
27
|
|
|
|
|
|
|
$req; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub override_request_method { |
31
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $req ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
3
|
my $method = $req->method; |
34
|
1
|
50
|
33
|
|
|
19
|
if ( $method && uc $method ne 'POST' ) { |
35
|
0
|
|
|
|
|
0
|
return $req; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
33
|
|
|
7
|
my $overload = $req->param( $self->METHOD_OVERRIDE_PARAM_KEY ) |
39
|
|
|
|
|
|
|
|| $req->header( $self->HTTP_METHOD_OVERRIDE_HEADER ); |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
33
|
|
|
142
|
if ( ($overload && grep { $_ eq $overload } @{ $self->HTTP_METHODS } ) != 0 ) { |
42
|
1
|
|
|
|
|
4
|
$req->method( uc $overload ); |
43
|
|
|
|
|
|
|
} |
44
|
1
|
|
|
|
|
2
|
$req; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__MIDDLEWARE__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
HTTP::Engine::Middleware::MethodOverride - simulate HTTP methods by query parameter |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $mw = HTTP::Engine::Middleware->new; |
58
|
|
|
|
|
|
|
$mw->install(qw/ HTTP::Engine::Middleware::MethodOverride /); |
59
|
|
|
|
|
|
|
HTTP::Engine->new( |
60
|
|
|
|
|
|
|
interface => { |
61
|
|
|
|
|
|
|
module => 'YourFavoriteInterfaceHere', |
62
|
|
|
|
|
|
|
request_handler => $mw->handler( \&handler ), |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
)->run(); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This module simulates the some minor HTTP methods by the query parameter(ex. DELETE, PUT). |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHORS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
dann |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |