line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Reproxy; |
2
|
1
|
|
|
1
|
|
826
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
7
|
use parent qw(Plack::Middleware); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.00004'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub call { |
7
|
4
|
|
|
4
|
1
|
52287
|
my ($self, $env) = @_; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
|
|
25
|
my $res = $self->app->( $env ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Otherwise, wait for headers |
12
|
|
|
|
|
|
|
return $self->response_cb( $res, sub { |
13
|
4
|
|
|
4
|
|
116
|
my $res = shift; |
14
|
|
|
|
|
|
|
|
15
|
4
|
50
|
|
|
|
22
|
if ($res->[0] ne '200') { |
16
|
|
|
|
|
|
|
# Not success, then just pass through |
17
|
0
|
|
|
|
|
0
|
return; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Now check header |
21
|
4
|
|
|
|
|
32
|
my $reproxy_url = Plack::Util::header_get( $res->[1], 'X-Reproxy-URL' ); |
22
|
4
|
100
|
|
|
|
124
|
if ($reproxy_url) { |
23
|
|
|
|
|
|
|
# it's a reproxy! |
24
|
2
|
|
|
|
|
13
|
$reproxy_url = URI->new($reproxy_url); |
25
|
2
|
50
|
|
|
|
141
|
if (! $reproxy_url->scheme) { |
26
|
0
|
|
|
|
|
0
|
$reproxy_url->scheme( $ENV{'psgi.url_scheme'} ); |
27
|
|
|
|
|
|
|
} |
28
|
2
|
50
|
|
|
|
31
|
if (! $reproxy_url->host) { |
29
|
0
|
|
0
|
|
|
0
|
$reproxy_url->host( $ENV{HTTP_HOST} || $ENV{SERVER_NAME} ); |
30
|
|
|
|
|
|
|
} |
31
|
2
|
|
|
|
|
56
|
return $self->reproxy_to( $res, $env, $reproxy_url ); |
32
|
|
|
|
|
|
|
} |
33
|
4
|
|
|
|
|
531
|
} ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub extract_headers { |
37
|
0
|
|
|
0
|
0
|
|
my ($self, $env) = @_; |
38
|
0
|
|
|
|
|
|
return map { |
39
|
0
|
|
|
|
|
|
(my $field = $_) =~ s/^HTTPS?_//; |
40
|
0
|
|
|
|
|
|
( $field => $env->{$_} ); |
41
|
0
|
|
|
|
|
|
} grep { /^(?:HTTP|CONTENT(?!_TYPE$)|COOKIE)/i } keys %$env; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |