line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::RemoteAddr; |
2
|
1
|
|
|
1
|
|
883
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
1
|
|
|
1
|
1
|
40
|
my ($self, $app, $conf) = @_; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
50
|
|
|
19
|
$conf->{order} ||= ['x-real-ip', 'tx']; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$app->helper( remote_addr => sub { |
12
|
2
|
|
|
2
|
|
67376
|
my $c = shift; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
5
|
foreach my $place ( @{ $conf->{order} } ) { |
|
2
|
|
|
|
|
11
|
|
15
|
3
|
100
|
|
|
|
17
|
if ( $place eq 'x-real-ip' ) { |
|
|
50
|
|
|
|
|
|
16
|
2
|
|
|
|
|
10
|
my $ip = $c->req->headers->header('X-Real-IP'); |
17
|
2
|
100
|
|
|
|
473
|
return $ip if $ip; |
18
|
|
|
|
|
|
|
} elsif ( $place eq 'tx' ) { |
19
|
1
|
|
|
|
|
25
|
my $ip = $c->tx->remote_address; |
20
|
1
|
50
|
|
|
|
179
|
return $ip if $ip; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return; |
25
|
1
|
|
|
|
|
11
|
}); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
__END__ |