| 1 | package HTTP::Session::State::Mixin::ResponseFilter; | ||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 3 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 3 | our @EXPORT_OK = qw/response_filter/; | |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 9 | ▶ | sub response_filter { | ||||||||||||||||||||||
|
Subroutine
response_filter: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||
| 8 | 9 | my ($self, $session_id, $res) = @_; | |||||||||||||||||||||||
| 9 | 9 | ▶ | Carp::croak "missing session_id" unless $session_id; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | 8 | ▶ | if (Scalar::Util::blessed $res) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 12 | 6 | ▶ | if ($res->code == 302) { | ||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||
| 13 | 2 | ▶ | if (my $uri = $res->header('Location')) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 14 | 1 | $res->header('Location' => $self->redirect_filter($session_id, $uri)); | |||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||
| 16 | 2 | return $res; | |||||||||||||||||||||||
| 17 | ▶ | } elsif ($res->content && ($res->header('Content-Type')||'text/html') =~ /html/) { | |||||||||||||||||||||||
|
Condition100%5/5
$res->content and ($res->header("Content-Type") || "text/html") =~ /html/
$res->header('Content-Type') || 'text/html'
MC/DC100%2/2
$res->content and ($res->header("Content-Type") || "text/html") =~ /html/
$res->content
$res->header('Content-Type')
Truth table100%3/3
A and B
A= $res->contentB= $res->header('Content-Type')
| |||||||||||||||||||||||||
| 18 | 2 | $res->content( $self->html_filter($session_id, $res->content) ); | |||||||||||||||||||||||
| 19 | 2 | return $res; | |||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||
| 21 | 2 | return $res; # nop | |||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||
| 23 | } else { | ||||||||||||||||||||||||
| 24 | # psgi | ||||||||||||||||||||||||
| 25 | 2 | ▶ | if ($res->[0] == 302) { | ||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||
| 26 | 1 | my @headers = @{ $res->[1] }; # copy | |||||||||||||||||||||||
| 27 | 1 | my @new_headers; | |||||||||||||||||||||||
| 28 | 1 | ▶ | while ( my ( $key, $val ) = splice @headers, 0, 2 ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 29 | 1 | ▶ | if (lc($key) eq 'location') { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 30 | 1 | $val = $self->redirect_filter($session_id, $val); | |||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||
| 32 | 1 | push @new_headers, $key, $val; | |||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||
| 34 | 1 | $res->[1] = \@new_headers; | |||||||||||||||||||||||
| 35 | 1 | return $res; | |||||||||||||||||||||||
| 36 | } elsif (my $body = $res->[2]) { | ||||||||||||||||||||||||
| 37 | 1 | ▶ | if ( ref $body eq 'ARRAY' ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 38 | # TODO: look the content-type header. | ||||||||||||||||||||||||
| 39 | 1 | my $content = ''; | |||||||||||||||||||||||
| 40 | 1 | for my $line (@$body) { | |||||||||||||||||||||||
| 41 | 1 | ▶ | $content .= $line if length $line; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||
| 43 | 1 | $res->[2] = [$self->html_filter($session_id, $content)]; | |||||||||||||||||||||||
| 44 | 1 | return $res; | |||||||||||||||||||||||
| 45 | } else { # HTTP::Session should not process glob. | ||||||||||||||||||||||||
| 46 | 0 | return $res; | |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||
| 49 | 0 | return $res; # nop | |||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||
| 54 | 3 | 1; | |||||||||||||||||||||||