| 1 | package Mojolicious::Plugin::RemoteAddr; | ||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | 1 | our $VERSION = '0.03'; | |||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 1 | ▶ | sub register { | ||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||
| 7 | 1 | my ($self, $app, $conf) = @_; | |||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 1 | ▶ | $conf->{order} ||= ['x-real-ip', 'x-forwarded-for', 'tx']; | ||||||||||||||||
|
Condition50%1/2
$conf->{"order"} ||= ["x-real-ip", "x-forwarded-for", "tx"]
MC/DC0%0/1
$conf->{"order"} ||= ["x-real-ip", "x-forwarded-for", "tx"]
$conf->{"order"}
Truth table50%1/2
A
A= $conf->{"order"}
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 2 | ▶ | $app->helper( remote_addr => sub { | ||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||
| 12 | 2 | my $c = shift; | |||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 2 | foreach my $place ( @{ $conf->{order} } ) { | |||||||||||||||||
| 15 | 4 | ▶ | if ( $place eq 'x-real-ip' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 16 | 2 | my $ip = $c->req->headers->header('X-Real-IP'); | |||||||||||||||||
| 17 | 2 | ▶ | return $ip if $ip; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 18 | } elsif ( $place eq 'x-forwarded-for' ) { | ||||||||||||||||||
| 19 | 1 | my $ip = $c->req->headers->header('X-Forwarded-For'); | |||||||||||||||||
| 20 | 1 | ▶ | return $ip if $ip; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 21 | } elsif ( $place eq 'tx' ) { | ||||||||||||||||||
| 22 | 1 | my $ip = $c->tx->remote_address; | |||||||||||||||||
| 23 | 1 | ▶ | return $ip if $ip; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 24 | } | ||||||||||||||||||
| 25 | } | ||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||
| 28 | 1 | }); | |||||||||||||||||
| 29 | } | ||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 1 | 1; | |||||||||||||||||
| 32 | __END__ | ||||||||||||||||||