line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Curlizer; |
2
|
2
|
|
|
2
|
|
72398
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
44
|
|
3
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
749
|
use String::ShellQuote qw/shell_quote/; |
|
2
|
|
|
|
|
1096
|
|
|
2
|
|
|
|
|
90
|
|
6
|
2
|
|
|
2
|
|
809
|
use Plack::Request; |
|
2
|
|
|
|
|
77110
|
|
|
2
|
|
|
|
|
47
|
|
7
|
2
|
|
|
2
|
|
10
|
use parent 'Plack::Middleware'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6
|
|
8
|
2
|
|
|
|
|
7
|
use Plack::Util::Accessor qw/ |
9
|
|
|
|
|
|
|
callback |
10
|
2
|
|
|
2
|
|
4181
|
/; |
|
2
|
|
|
|
|
2
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub call { |
15
|
2
|
|
|
2
|
1
|
12223
|
my($self, $env) = @_; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
10
|
my $req = Plack::Request->new($env); |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
14
|
my $curl = $self->_build_curl_cmd($req); |
20
|
|
|
|
|
|
|
|
21
|
2
|
50
|
33
|
|
|
181
|
if ($self->callback && ref($self->callback) eq 'CODE') { |
22
|
2
|
|
|
|
|
60
|
$self->callback->($curl, $req, $env); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
17
|
my $res = $self->app->($env); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _build_curl_cmd { |
29
|
2
|
|
|
2
|
|
2
|
my ($self, $req) = @_; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
4
|
my @cmd = ('curl', $req->uri); |
32
|
|
|
|
|
|
|
|
33
|
2
|
100
|
|
|
|
418
|
unless ($req->method eq 'GET') { |
34
|
1
|
|
|
|
|
6
|
push @cmd, '-X', $req->method; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
12
|
my $http_header_str = $req->headers->as_string; |
38
|
2
|
|
|
|
|
240
|
my @headers = split "\n", $http_header_str; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
3
|
for my $h (@headers) { |
41
|
5
|
|
|
|
|
13
|
my ($k, $v) = split /:\s+/, $h; |
42
|
5
|
|
|
|
|
11
|
push @cmd, '-H', qq|$k: $v|; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
100
|
|
|
|
4
|
if ($req->method eq 'POST') { |
46
|
1
|
|
|
|
|
8
|
push @cmd, '--data', $req->content; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
439
|
return shell_quote @cmd; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |