line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Proxy::ByHeader; |
2
|
1
|
|
|
1
|
|
32033
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use parent 'Plack::Middleware'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
25118
|
use Plack::Util::Accessor qw(header allowed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
1239
|
use Plack::Request; |
|
1
|
|
|
|
|
109704
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
12
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
460
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub prepare_app { |
14
|
10
|
|
|
10
|
1
|
10992
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
10
|
100
|
|
|
|
33
|
$self->header( ['Host'] ) if !defined $self->header; |
17
|
10
|
100
|
|
|
|
186
|
$self->allowed( [] ) if !defined $self->allowed; |
18
|
|
|
|
|
|
|
|
19
|
10
|
100
|
|
|
|
78
|
croak("argument to 'allowed' must be an array reference") |
20
|
|
|
|
|
|
|
if not( ref( $self->allowed ) eq 'ARRAY' ); |
21
|
|
|
|
|
|
|
|
22
|
9
|
100
|
|
|
|
64
|
croak("argument to 'header' must be an array reference") |
23
|
|
|
|
|
|
|
if not( ref( $self->header ) eq 'ARRAY' ); |
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
|
|
55
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub call { |
29
|
8
|
|
|
8
|
1
|
84036
|
my ( $self, $env ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
8
|
|
|
|
|
131
|
my $req = Plack::Request->new($env); |
32
|
8
|
|
|
|
|
118
|
my $uri = $req->uri; |
33
|
|
|
|
|
|
|
|
34
|
8
|
|
|
|
|
2167
|
my $host; |
35
|
8
|
|
|
|
|
11
|
for my $header ( @{$self->header} ) { |
|
8
|
|
|
|
|
55
|
|
36
|
7
|
|
|
|
|
63
|
$host = $req->header($header); |
37
|
7
|
100
|
|
|
|
1146
|
last if $host; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
8
|
100
|
|
|
|
37
|
if ($host) { |
41
|
6
|
|
|
|
|
102
|
my $host = (split(/\s*,\s*/,$host))[-1]; |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
12
|
my $allow = 1; |
44
|
6
|
100
|
|
|
|
7
|
if ( @{ $self->allowed } ) { |
|
6
|
|
|
|
|
20
|
|
45
|
5
|
|
|
|
|
41
|
my %allowed = map { $_ => 1 } @{ $self->allowed }; |
|
8
|
|
|
|
|
46
|
|
|
5
|
|
|
|
|
16
|
|
46
|
5
|
100
|
|
|
|
26
|
$allow = 0 if not $allowed{$host}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
6
|
100
|
|
|
|
20
|
if ($allow) { |
50
|
5
|
|
|
|
|
17
|
$uri->host($host); |
51
|
5
|
|
|
|
|
753
|
$env->{'plack.proxy.url'} = $uri; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
8
|
|
|
|
|
37
|
return $self->app->($env); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |