| 1 | package Plack::Middleware::XSendfile; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use parent qw(Plack::Middleware); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::Util::Accessor qw( variation ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 1 | Carp::carp("Plack::Middleware::XSendfile is deprecated and will be removed in a future release"); | |||||||||||||||||||||||||||
| 14 | 1 | $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=0.8
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 1 | my $env = shift; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | my $res = $self->app->($env); | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | $self->response_cb($res, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=33.2
| |||||||||||||||||||||||||||||
| 23 | 1 | my $res = shift; | |||||||||||||||||||||||||||
| 24 | 1 | my($status, $headers, $body) = @$res; | |||||||||||||||||||||||||||
| 25 | 1 | ▶ | return unless defined $body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | if (Scalar::Util::blessed($body) && $body->can('path')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($body) and $body->can("path")
MC/DC0%0/2
builtin::blessed($body) and $body->can("path")
builtin::blessed($body)
$body->can("path")
Truth table33%1/3
A and B
A= builtin::blessed($body)B= $body->can("path")
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my $type = $self->_variation($env) || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_variation($env) || ''
MC/DC0%0/1
$self->_variation($env) || ''
$self->_variation($env)
Truth table50%1/2
A
A= $self->_variation($env)
| |||||||||||||||||||||||||||||
| 29 | 1 | my $h = Plack::Util::headers($headers); | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ($type && !$h->exists($type)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type and not $h->exists($type)
MC/DC0%0/2
$type and not $h->exists($type)
$type
not $h->exists($type)
Truth table33%1/3
A and not(B)
A= $typeB= not $h->exists($type)
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | if ($type eq 'X-Accel-Redirect') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 0 | my $path = $body->path; | |||||||||||||||||||||||||||
| 33 | 0 | my $url = $self->map_accel_path($env, $path); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | $h->set($type => $url) if $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $h->set('Content-Length', 0); | |||||||||||||||||||||||||||
| 36 | 0 | $body = []; | |||||||||||||||||||||||||||
| 37 | ▶ | } elsif ($type eq 'X-Sendfile' or $type eq 'X-Lighttpd-Send-File') { | |||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "X-Sendfile" or $type eq "X-Lighttpd-Send-File"
MC/DC0%0/2
$type eq "X-Sendfile" or $type eq "X-Lighttpd-Send-File"
$type eq "X-Sendfile"
$type eq "X-Lighttpd-Send-File"
Truth table33%1/3
A or B
A= $type eq "X-Sendfile"B= $type eq "X-Lighttpd-Send-File"
| |||||||||||||||||||||||||||||
| 38 | 1 | my $path = $body->path; | |||||||||||||||||||||||||||
| 39 | 1 | ▶ | $h->set($type => $path) if defined $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | $h->set('Content-Length', 0); | |||||||||||||||||||||||||||
| 41 | 1 | $body = []; | |||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||
| 43 | 0 | $env->{'psgi.errors'}->print("Unknown x-sendfile variation: $type"); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | @$res = ( $status, $headers, $body ); | |||||||||||||||||||||||||||
| 49 | 1 | }); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub map_accel_path { | ||||||||||||||||||||||||||
|
Subroutine
map_accel_path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my($self, $env, $path) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (my $mapping = $env->{HTTP_X_ACCEL_MAPPING}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | my($internal, $external) = split /=/, $mapping, 2; | |||||||||||||||||||||||||||
| 57 | 0 | $path =~ s!^\Q$internal\E!$external!i; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $path; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub _variation { | ||||||||||||||||||||||||||
|
Subroutine
_variation: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||
| 64 | 1 | my($self, $env) = @_; | |||||||||||||||||||||||||||
| 65 | 1 | ▶ | $self->variation || $env->{'plack.xsendfile.type'} || $env->{HTTP_X_SENDFILE_TYPE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->variation or $env->{"plack.xsendfile.type"}
MC/DC0%0/2
$self->variation or $env->{"plack.xsendfile.type"}
$self->variation
$env->{"plack.xsendfile.type"}
Truth table33%1/3
A or B
A= $self->variationB= $env->{"plack.xsendfile.type"}
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||