File Coverage

blib/lib/Mojolicious/Plugin/ProxyPassReverse/SubDir.pm
Criterion Covered Total %
statement 16 16 100.0
branch 3 4 75.0
condition 4 9 44.4
subroutine 3 3 100.0
pod 1 1 100.0
total 27 33 81.8


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::ProxyPassReverse::SubDir;
2 2     2   148437 use Mojo::Base 'Mojolicious::Plugin';
  2         14467  
  2         19  
3              
4             our $VERSION = '0.02';
5              
6             sub register {
7 1     1 1 42 my ($self, $app, $conf) = @_;
8              
9 1   50     5 $conf //= {};
10 1   50     9 my $header = $conf->{header} // 'X-Forwarded-Host';
11 1         2 my $value = $conf->{value};
12 1   50     5 my $depth = $conf->{depth} // 1;
13              
14             $app->hook(before_dispatch => sub {
15 2     2   13828 my $c = shift;
16              
17 2 100       17 if ( defined ( my $v = $c->req->headers->header($header) ) ) {
18 1 50 33     31 return if defined $value and $v ne $value;
19              
20             DEPTH:
21 1         4 for ( 1 .. $depth ) {
22 1         7 push @{ $c->req->url->base->path->parts },
23 1         2 shift @{ $c->req->url->path->parts };
  1         84  
24             }
25             }
26 1         10 });
27             }
28              
29             1;
30             __END__